package com.tulele.vtool.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tulele.vtool.mapper.ArticleLookDetailLogMapper;
import com.tulele.vtool.mapper.ArticleTypeInfoMapper;
import com.tulele.vtool.mapper.SysGzhMapper;
import com.tulele.vtool.model.*;
import com.tulele.vtool.model.combinedEntity.*;
import com.tulele.vtool.model.logEntity.ArticleLookDetailLog;
import com.tulele.vtool.model.logEntity.PageDetailLog;
import com.tulele.vtool.model.reqEntity.*;
import com.tulele.vtool.model.respEntity.ArticleRespEntity;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.*;
import com.tulele.vtool.service.impl.ArticleInfoServiceImpl;
import com.tulele.vtool.task.async.AddUserShareArticleInfoAsyncTask;
import com.tulele.vtool.task.async.LookArticleAsyncTask;
import com.tulele.vtool.utils.*;
import com.tulele.vtool.wechat.service.WeixinService;
import com.tulele.vtool.wechat.service.WeixinServiceDL;
import com.tulele.vtool.wechat.service.WeixinServiceMap;
import com.tulele.vtool.wechat.service.WeixinServiceNew;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.checkerframework.checker.units.qual.Area;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.tulele.vtool.utils.AesExpand.aesEncrypt;
import static com.tulele.vtool.utils.SysConstant.OSS_PAR_80_80;

@Slf4j
@RestController
public class ArticleInfoHandler {

    @Autowired
    private IArticleInfoService articleInfoService;

    @Autowired
    private IUserInfoService userInfoService;

    @Autowired
    private IBrandInfoService brandInfoService;

    @Autowired
    private IUserArticleProcessService userArticleProcessService;

    @Autowired
    private IUserArticleTypeInfoService userArticleTypeInfoService;

    @Autowired
    private IUserRelateArticleTypeInfoService userRelateArticleTypeInfoService;

    @Autowired
    private IUserBrandInfoService userBrandInfoService;

    @Autowired
    private IUserCommodityInfoService userCommodityInfoService;

    @Autowired
    private IArticleHeadTailTemplateInfoService articleHeadTailTemplateInfoService;

    @Autowired
    @Lazy
    private LookArticleAsyncTask lookArticleAsyncTask;

    @Autowired
    private IUserPunchClockInfoService userPunchClockInfoService;

    @Autowired
    private RedisCacheUtil redisCacheUtil;

    @Autowired
    private IBrandSupplyInfoService brandSupplyInfoService;

    @Autowired
    private ILookArticleInfoService lookArticleInfoService;

    @Autowired
    private IArticleBrandAndTypeInfoService articleBrandAndTypeInfoService;

    @Autowired
    private AddUserShareArticleInfoAsyncTask addUserShareArticleInfoAsyncTask;

    @Autowired
    private IArticleTypeInfoService articleTypeInfoService;

//    @Autowired
//    private WeixinService weixinService;

    @Autowired
    private ObjectFactory<WeixinServiceDL> objectFactory;

    @Autowired
    private ConnectionInfoService connectionInfoService;

//    @Value("${spring.profiles.active}")
//    private String springProfilesActive;

//    @Autowired
//    private SysGzhMapper sysGzhMapper;
    @Autowired
    private SysGzhService sysGzhService;

    @Autowired
    private ArticleLookDetailLogMapper articleLookDetailLogMapper;

//    @Autowired
//    private PlatformSysInfoConfig platformSysInfoConfig;

    /**
     * 服务对象
     */
    @Autowired
    private BArticleIllustrateService bArticleIllustrateService;

//    @Value("${isDrainage}") //是否引流到 其它公众号
//    private String isDrainage;

    private static final String TRICKORTREAT = "TRICKORTREAT:";

    @Autowired
    @Qualifier("redisTemplate")
    public RedisTemplate redisTemplate;

    /**
     * 服务对象
     */
    @Resource
    private BDecorationArticlesService bDecorationArticlesService;

    @Autowired
    private ArticleTypeInfoMapper articleTypeInfoMapper;

    /**
     * 服务对象
     */
    @Autowired
    private BBusinessInfoService bBusinessInfoService;

    @Autowired
    private BPosterInfoService bPosterInfoService;

    @Autowired
    private IUserShareArticleInfoService userShareArticleInfoService;

    @Autowired
    private ArticleTableInfoService articleTableInfoService;

    @Autowired
    private ArticleTailAdvertInfoService articleTailAdvertInfoService;


    @GetMapping(value = "/getConfigByGzh", produces = "application/json;charset=UTF-8")
    public RespData getConfigByGzh(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying) {

        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(identifying);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(10);
        resultMap.put("cooperationUrl", platformSysInfo.getCooperationUrl());
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 获取用户的文章类型
     * @param userId 用户编号
     * @return 用户的文章类型列表
     */
    @PostMapping(value = "/getArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData getArticleTypeInfo(@RequestHeader("userId") String userId) {

        List<CombinedUserArticleTypeInfo> articleTypeInfo = userArticleTypeInfoService.getUserPersonalArticleTypeInfo(Integer.parseInt(userId));

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleTypeInfo", articleTypeInfo);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @GetMapping(value = "/getServerByArticleId", produces = "application/json;charset=UTF-8")
    public RespData getServerByArticleId(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying, @RequestParam Integer articleId, @RequestParam Integer shareUserId) {

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        SysGzh sysGzh = null;

        Integer concernStatus = null;
        Integer type = 0;
        String subscribeUrl = "";
        String serverUrl = "";
        String gzhName = "";

        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(identifying);


        if (platformSysInfo.getSysGzh().getIsDrainage() != null && platformSysInfo.getSysGzh().getIsDrainage().equals(1)) { //这个等于1 才导流
            ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);
            if (articleInfo != null && articleInfo.getArticleBrandId() != null) {
                GzhBrandMap gzhBrandMap = sysGzhService.getGzhBrandMap(articleInfo.getArticleBrandId());

                if (gzhBrandMap != null) {

                    if (gzhBrandMap.getIsRandom().equals(1)) {  //随机显示关注
                        long t = System.currentTimeMillis();
                        if (t % 2 == 1) {   //是奇数
                            type = 1;
                        } else {
                            type = 0;
                        }
                    } else {
                        type = 1;
                    }

                    sysGzh = sysGzhService.selectCacheLinkByGzhCode(gzhBrandMap.getGzhCode());

                    //20200717 二维码参数中添加参数 文章分配人ID_文章ID_当前用户ID
                    subscribeUrl = sysGzh.getSubscribeUrl();
                    serverUrl = sysGzh.getServerUrl();
                    gzhName = sysGzh.getGzhName();
                    //+ "&scene=t_" + shareUserId + "_" + articleId + "_" + userId+ "&key=t_" + shareUserId + "_" + articleId + "_" + userId;

                    GzhUserMap gzhUserMap = sysGzhService.getGzhUserMap(Integer.parseInt(userId), gzhBrandMap.getGzhCode());

                    if (gzhUserMap != null) {
                        concernStatus = userInfoService.getUserConcernStatus_zktdb(gzhUserMap.gettUserId(), gzhBrandMap.getGzhCode()); //先看主库有没有
                        if (concernStatus == null) {
                            concernStatus = userInfoService.getUserConcernStatus_gzhdbjssq(gzhUserMap.gettUserId(), gzhBrandMap.getGzhCode());//再看子库有没有
                        }
                    }
                }
            }
        }

        resultMap.put("type", type);
        resultMap.put("concernStatus", (concernStatus == null ? 0 : concernStatus));
        resultMap.put("subscribeUrl", subscribeUrl);
        //resultMap.put("serverUrl",serverUrl);//20201120 改成统一由自己服务器生成二维码，通过这个文章 的品牌对应的 公众号 来生成
        resultMap.put("serverUrl", platformSysInfo.getSysGzh().getServerUrl());//在接口generatePublicNumQrCode中直接判断 文章 所属品牌的公众号
        resultMap.put("gzhName", gzhName);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @GetMapping(value = "/sendArticleByGzh", produces = "application/json;charset=UTF-8")
    public RespData sendArticleByGzh(@RequestHeader("userId") String userId, @RequestParam Integer articleId) throws WxErrorException {

        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);

        SysGzh sysGzh = null;
        if (articleInfo != null && articleInfo.getArticleBrandId() != null) {
            GzhBrandMap gzhBrandMap = sysGzhService.getGzhBrandMap(articleInfo.getArticleBrandId());

            if (gzhBrandMap != null) {
                sysGzh = sysGzhService.selectCacheLinkByGzhCode(gzhBrandMap.getGzhCode());

                GzhUserMap gzhUserMap = sysGzhService.getGzhUserMap(Integer.parseInt(userId), gzhBrandMap.getGzhCode());

                if (gzhUserMap != null) {
                    //WxMpServiceImpl wxNewMpService = WeixinServiceNew.getWeixinService(sysGzh);
                    WeixinServiceDL wxNewMpService= WeixinServiceMap.getWeixinService(gzhBrandMap.getGzhCode());
                    WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                    wxArticle.setTitle(articleInfo.getArticleTitle());
                    wxArticle.setDescription(articleInfo.getArticleDesc());
                    wxArticle.setPicUrl(articleInfo.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                    //拼接链接地址
                    String accessUrl = sysGzh.getRealmMessage() +"pages/article/detail.html?articleId="+ articleId;

                    if (articleInfo.getResourceType().equals(2)) {//如果是视频
                        accessUrl = accessUrl.replace("/article/", "/video/");
                        accessUrl = accessUrl.replace("/detail.html?", "/index.html?");
                        //accessUrl=accessUrl+"&userId="+ userId +"&viewType=2";
                        accessUrl = accessUrl + "&userId=" + userId + "&t=2";
                    }

                    wxArticle.setUrl(accessUrl);

                    WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(gzhUserMap.gettOpenid()).build();
                    try {
                        wxNewMpService.getKefuService().sendKefuMessage(testMsg);
                    } catch (WxErrorException e) {
                        // 发送模板消息接口
                        WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                                // 接收者openid
                                .toUser(gzhUserMap.gettOpenid())
                                // 模板id
                                .templateId(sysGzh.getGroundingTempId())
                                // 模板跳转链接
                                .url(accessUrl)
                                .build();

                        String firstMsg = "⭕您好，您订阅的素材已经送达，点这领取！";

                        // 添加模板数据
                        templateMessage.addData(new WxMpTemplateData("first", firstMsg, "#FF00FF"))
                                .addData(new WxMpTemplateData("keyword1", "(已带上您的名片)", "#FF00FF"))
                                .addData(new WxMpTemplateData("keyword2", articleInfo.getArticleTitle() + "\n", "#FF00FF"))
                                .addData(new WxMpTemplateData("remark", "🔴回复数字【 6 】  加客服领取销售开单秘籍一份\n🔴回复数字【 9 】  获取品牌更多引流爆文视频！", "#FF0000"));

                        wxNewMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);

                        e.printStackTrace();
                    }
                }
            }
        }
        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        //respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }




    @PostMapping(value = "/getVideoInfo", produces = "application/json;charset=UTF-8")
    public RespData getVideoInfo(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying, @RequestParam Integer articleId, @RequestParam(required=false) String shareUserId, @RequestParam(required=false) String t) throws Exception {

        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);

        if(articleInfo.getArticleDesc() == null){
            articleInfo = articleInfoService.getArticleDetailByInfo(articleId);
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(25);

        int userIdInt = Integer.parseInt(userId);

//        ArticleLookDetailLog articleLookDetailLog=new ArticleLookDetailLog();
//        articleLookDetailLog.setArticleId(articleInfo.getId());
//        articleLookDetailLog.setUserId(userIdInt);
//        articleLookDetailLog.setGzhCode(identifying);//公众号标记
//        articleLookDetailLog.setLookTime(new Date());
//        articleLookDetailLog.setResourceType(2);
//        addLookLog(articleLookDetailLog);

        Integer articleUserId = articleInfo.getUserId();

        //如果不存在文章用户ID，则认为是平台文章，此时展示当前用户自己的信息
        if (articleUserId == null) {
            if (StringUtils.isNotBlank(shareUserId) && StringUtils.isNumeric(shareUserId)) {
                articleUserId = Integer.parseInt(shareUserId);
                //20200401 添加邀请按钮设置
                WxNotifyMsgSetInfo userNotifyMsgSetInfo= userInfoService.getUserNotifySetInfo(articleUserId);
                if(userNotifyMsgSetInfo!=null){
                    resultMap.put("inviteSetStatus", userNotifyMsgSetInfo.getInviteSetStatus());
                }
            } else {
                articleUserId = Integer.parseInt(userId);
            }
        }else{
            //20200401 添加邀请按钮设置
            WxNotifyMsgSetInfo userNotifyMsgSetInfo= userInfoService.getUserNotifySetInfo(articleUserId);
            if(userNotifyMsgSetInfo!=null){
                resultMap.put("inviteSetStatus", userNotifyMsgSetInfo.getInviteSetStatus());
            }
        }


        List<VidoeListDto> videoList = new ArrayList<VidoeListDto>();

        VidoeListDto vidoe1 = new VidoeListDto();
        vidoe1.setId(articleId);
        vidoe1.setUrl(articleInfo.getVideoUrl());//视频url
        vidoe1.setCover(articleInfo.getArticleImgUrl());//视频摘要图片
        //vidoe1.setDes(articleInfo.getArticleContent().length() > 50 ? articleInfo.getArticleContent().substring(50) + "…" : articleInfo.getArticleContent());//摘要
        vidoe1.setDes(articleInfo.getArticleContent());
        vidoe1.setTitle(articleInfo.getArticleTitle());//标题
        vidoe1.setShareDes(articleInfo.getArticleDesc());//分享配文
        vidoe1.setVideoHeight(articleInfo.getVideoHeight());// 视频高度


        UserInfo userInfo = userInfoService.getUserMainInfo(Integer.valueOf(articleUserId));

        //控制分享这个视频的人 的信息显示
        //if(userInfo.getVipStatus()!=null && userInfo.getVipStatus().equals(1)) {//是会员 屏蔽于 20200511
            vidoe1.setAuthor_id(userInfo.getUserId());
            vidoe1.setAuthor(userInfo.getNickName());
            vidoe1.setTag_image(userInfo.getAvatarUrl());//用户头像
            vidoe1.setQrcode_url(userInfo.getQrcodeUrl());//微信二维码
            vidoe1.setTelNum(userInfo.getTelNum());//电话
//        }else{ //非会员
//            try {
//                vidoe1.setAuthor_id(userInfo.getUserId());
//                vidoe1.setAuthor(userInfo.getNickName().substring(0, 1) + "******");
//                vidoe1.setTag_image("../../img/gzh_logo.jpg");//用户头像
//                vidoe1.setQrcode_url("../../img/erwema_tui@2x.png");//微信二维码
//                vidoe1.setTelNum(userInfo.getTelNum().length() >= 3 ? userInfo.getTelNum().substring(0, 2) + "********" : "138********");//电话
//            }catch (Exception e){}
//        }
        vidoe1.setFabulous(false);
        vidoe1.setTagFollow(false);

        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(identifying);
        //String[] realmArr = {platformSysInfo.getShareDomainUrl(),platformSysInfo.getFrontDomain(),platformSysInfo.getSysGzh().getRealmResource()};
        String[] realmArr = {platformSysInfo.getShareDomainUrl()};
        int index = (int) (Math.random() * realmArr.length);
        String mainlink=realmArr[index];

        vidoe1.setMainLink(mainlink);

        videoList.add(vidoe1);


        //如果存在文章用户ID，且文章用户ID和当前用户ID不一样，则认为是A查看了B的文章
        Integer lookArticleLogId = 0;
        if (articleUserId != null && articleUserId.intValue() != userIdInt) {

            LookArticleInfo lookArticleInfo = new LookArticleInfo();
            lookArticleInfo.setUserId(userIdInt);
            lookArticleInfo.setOtherUserId(articleUserId);
            lookArticleInfo.setArticleId(articleId);

            UserInfo lookUserInfo = userInfoService.getUserMainInfo(userIdInt);

            lookArticleLogId = articleInfoService.lookOtherUserArticleSyn(lookArticleInfo, articleInfo, lookUserInfo.getNickName(), t,identifying);

        }

        /* 20210707 start hyl */
        Integer returnLookArticleId = Optional.ofNullable(lookArticleInfoService.returnLookArticleId(lookArticleLogId)).orElse(articleId);
        /* 20210707 end hyl */
        ArticleLookDetailLog articleLookDetailLog=new ArticleLookDetailLog();
        articleLookDetailLog.setArticleId(returnLookArticleId);
        articleLookDetailLog.setUserId(userIdInt);
        articleLookDetailLog.setGzhCode(identifying);
        articleLookDetailLog.setLookTime(new Date());
        articleLookDetailLog.setResourceType(2);
        articleLookDetailLog.setLookArticleLogId(lookArticleLogId);
        articleLookDetailLog.setLookEndTime(new Date());
        articleLookDetailLog.setSpentTime(0);
        int articleLookDetailLogId = Optional.ofNullable(addLookLog(articleLookDetailLog)).orElse(0);

        resultMap.put("articleLookDetailLogId", String.valueOf(articleLookDetailLogId));


        //UserInfo userInfo = userInfoService.getUserMainInfo(articleUserId);
        //文章所有者的用户信息
        resultMap.put("userId", String.valueOf(userInfo.getUserId()));
        vidoe1.setUserId(userInfo.getUserId());//用于保存转发、分享时的用户Id 20210611
        resultMap.put("nickName", userInfo.getNickName());
        resultMap.put("avatarUrl", userInfo.getAvatarUrl());
        resultMap.put("signature", userInfo.getSignature());

        resultMap.put("qrcodeUrl", userInfo.getQrcodeUrl());
        resultMap.put("telNum", userInfo.getTelNum());


        //获取用户选中的品牌信息(有效微站)
        BrandInfo selectBrandInfo = userBrandInfoService.getUserSelectBrandInfo(articleUserId);
        String userBrandName = "";
        if (selectBrandInfo != null) {
            userBrandName = selectBrandInfo.getBrandName();
        }
        resultMap.put("userBrandName", userBrandName);

        //当前用户关注公众号状态
        int concernStatus = Optional.ofNullable(userInfoService.getUserConcernStatus(Integer.parseInt(userId))).orElse(0);
        resultMap.put("concernStatus", concernStatus);
        resultMap.put("curUserId", userId);

        resultMap.put("articleTitle", articleInfo.getArticleTitle());
        resultMap.put("articleImgUrl", articleInfo.getArticleImgUrl());
        resultMap.put("articleId", articleInfo.getId());

        int articleVersionNum = Optional.ofNullable(articleInfo.getArticleVersionNum()).orElse(1);
        //if (SysConstant.ARTICLE_VERSION_NUM_OF_ORIGINAL_FORMAT == articleVersionNum) { //20210222 全部都是新版，没有必要判断，这个字段 用作其它业务

            resultMap.put("articleInfo", articleInfo.getArticleContent());

//        } else {
//
//            resultMap.put("articleInfo", JSONObject.parseArray(articleInfo.getArticleContent(), ArticleContentInfo.class));
//
//        }

        resultMap.put("articleSource", Optional.ofNullable(articleInfo.getArticleSource()).orElse(1));

        String articleDesc = Optional.ofNullable(articleInfo.getArticleDesc()).orElse(articleInfo.getArticleTitle());
        if (StringUtils.isBlank(articleDesc)) {
            articleDesc = articleInfo.getArticleTitle();
        }

        resultMap.put("articleDesc", articleDesc);

        resultMap.put("headAdContent", articleInfo.getHeadAdContent());
        resultMap.put("tailAdContent", articleInfo.getTailAdContent());

        resultMap.put("articleVersionNum", articleVersionNum);

        List<ArticleHeadTailTemplateInfo> articleHeadTailTemplateInfoList = articleHeadTailTemplateInfoService.getUserGlobalHtTemplateInfo(articleUserId);
        if (!CollectionUtils.isEmpty(articleHeadTailTemplateInfoList)) {

            articleHeadTailTemplateInfoList.forEach(info -> {

                int htPosition = Optional.ofNullable(info.getHtTemplatePosition()).orElse(1);
                if (htPosition == 1) {
                    resultMap.put("headAdContent", info.getHtTemplateContent());
                } else if (htPosition == 2) {
                    resultMap.put("tailAdContent", info.getHtTemplateContent());
                }

            });

        }

        //如果是自己的文章，则以文章本身的头尾为准
        if (articleUserId != null && articleUserId.intValue() == userIdInt) {

            String headAdContent = articleInfo.getHeadAdContent();
            if (StringUtils.isNotBlank(headAdContent)) {
                resultMap.put("headAdContent", headAdContent);
            }

            String tailAdContent = articleInfo.getTailAdContent();
            if (StringUtils.isNotBlank(tailAdContent)) {
                resultMap.put("tailAdContent", tailAdContent);
            }

        }

        resultMap.put("articleTypeId", articleInfo.getArticleTypeId());
        resultMap.put("articleBrandId", articleInfo.getArticleBrandId());

        //告知前端用户是否已经分享过文章
        int userShareArticleCount = Optional.ofNullable(articleInfoService.getUserSharedArticleCount(Integer.parseInt(userId))).orElse(0);
        resultMap.put("userShareArticleCount", userShareArticleCount);

        lookArticleAsyncTask.modifyArticleReadCount(articleId, t);

        UserInfo curUserInfo = userInfoService.getUserMainInfo(Integer.valueOf(userId));
        if(curUserInfo!=null){
            resultMap.put("curUser", curUserInfo);
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        resultMap.put("videoList", videoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getVideoList", produces = "application/json;charset=UTF-8")
    public RespData getVideoList(@RequestHeader("userId") String userId) {

        List<VidoeListDto> videoList = new ArrayList<VidoeListDto>();

        VidoeListDto vidoe1 = new VidoeListDto();
        vidoe1.setUrl("http://video.jishiyoo.com/3720932b9b474f51a4cf79f245325118/913d4790b8f046bfa1c9a966cd75099f-8ef4af9b34003bd0bc0261cda372521f-ld.mp4");
        vidoe1.setCover("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226124585&di=0ba2374046cd3e4183e9fbb5019638e6&imgtype=0&src=http%3A%2F%2Fimg.ladypai.com%2Fd%2Ffile%2F201811280851%2Fddaf331c-f19e-4b52-b25e-d963242795d4.jpg");
        vidoe1.setTag_image("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226005502&di=6c8c3418d820e75998269b611378b764&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201802%2F20%2F20180220165946_RiGPS.thumb.700_0.jpeg");
        vidoe1.setFabulous(false);
        vidoe1.setTagFollow(false);
        vidoe1.setAuthor_id(7);
        vidoe1.setAuthor("黄钰樑");
        vidoe1.setDes("武汉加油");
        videoList.add(vidoe1);

        VidoeListDto vidoe2 = new VidoeListDto();
        vidoe2.setUrl("http://video.jishiyoo.com/1eedc49bba7b4eaebe000e3721149807/d5ab221b92c74af8976bd3c1473bfbe2-4518fe288016ee98c8783733da0e2da4-ld.mp4");
        vidoe2.setCover("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226109691&di=0773445c48ea5cd2aaed9f1e44c0020d&imgtype=0&src=http%3A%2F%2Fimg.jk51.com%2Fimg_jk51%2F340948807.jpeg");
        vidoe2.setTag_image("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226022248&di=7b76a022d985cffc63970d838cd27744&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201410%2F09%2F20141009224754_AswrQ.jpeg");
        vidoe2.setFabulous(false);
        vidoe2.setTagFollow(false);
        vidoe2.setAuthor_id(7);
        vidoe2.setAuthor("黄钰樑");
        vidoe2.setDes("武汉加油");
        videoList.add(vidoe2);

        VidoeListDto vidoe3 = new VidoeListDto();
        vidoe3.setUrl("http://video.jishiyoo.com/161b9562c780479c95bbdec1a9fbebcc/8d63913b46634b069e13188b03073c09-d25c062412ee3c4a0758b1c48fc8c642-ld.mp4");
        vidoe3.setCover("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226088591&di=619c186f65e892135b4617c313b9fbc2&imgtype=0&src=http%3A%2F%2Fwx4.sinaimg.cn%2Forj360%2F8446b893gy1g95g6d93pmj20fo0nm0v8.jpg");
        vidoe3.setTag_image("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582226045861&di=9f6829cf19d7d6fb728c25945bf289a9&imgtype=0&src=http%3A%2F%2Fgss0.baidu.com%2F9vo3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2Fbba1cd11728b4710a0816c6ac9cec3fdfd0323ed.jpg");
        vidoe3.setFabulous(false);
        vidoe3.setTagFollow(false);
        vidoe3.setAuthor_id(7);
        vidoe3.setAuthor("黄钰樑");
        vidoe3.setDes("武汉加油");
        videoList.add(vidoe3);

        VidoeListDto vidoe4 = new VidoeListDto();
        vidoe4.setUrl("http://video.jishiyoo.com/3720932b9b474f51a4cf79f245325118/913d4790b8f046bfa1c9a966cd75099f-8ef4af9b34003bd0bc0261cda372521f-ld.mp4");
        vidoe4.setCover("http://oss.jishiyoo.com/images/file-1575341210559.png");
        vidoe4.setTag_image("http://npjy.oss-cn-beijing.aliyuncs.com/images/file-1575449277018pF3XL.jpg");
        vidoe4.setFabulous(false);
        vidoe4.setTagFollow(false);
        vidoe4.setAuthor_id(7);
        vidoe4.setAuthor("黄钰樑");
        vidoe4.setDes("武汉加油");
        videoList.add(vidoe4);

        VidoeListDto vidoe5 = new VidoeListDto();
        vidoe5.setUrl("http://video.jishiyoo.com/3720932b9b474f51a4cf79f245325118/913d4790b8f046bfa1c9a966cd75099f-8ef4af9b34003bd0bc0261cda372521f-ld.mp4");
        vidoe5.setCover("http://oss.jishiyoo.com/images/file-1575341210559.png");
        vidoe5.setTag_image("http://npjy.oss-cn-beijing.aliyuncs.com/images/file-1575449277018pF3XL.jpg");
        vidoe5.setFabulous(false);
        vidoe5.setTagFollow(false);
        vidoe5.setAuthor_id(7);
        vidoe5.setAuthor("黄钰樑");
        vidoe5.setDes("武汉加油");
        videoList.add(vidoe5);


        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("videoList", videoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getIntentionCustomerStatisInfo", produces = "application/json;charset=UTF-8")
    public RespData getIntentionCustomerStatisInfo(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying) {

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(7);

        //先查询是否是否关注了公众号
        int userConcernStatus = Optional.ofNullable(userInfoService.getUserConcernStatus(Integer.valueOf(userId))).orElse(0);
        if (userConcernStatus == 0) {

            resultMap.put("concernStatus", userConcernStatus);

            respData.setData(resultMap);
            respData.setMsg("成功");
            return respData;

        }

        resultMap.put("concernStatus", userConcernStatus);

        int vipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(Integer.valueOf(userId))).orElse(0);

        LookArticleStatisEntity totalTlookArticleStatisInfo = lookArticleInfoService.getTotalLookArticleStatisInfo(Integer.valueOf(userId));

        int totalLookCount = 0;
        if (totalTlookArticleStatisInfo != null) {

            totalLookCount = Optional.ofNullable(totalTlookArticleStatisInfo.getTotalLookCount()).orElse(0);
            resultMap.put("totalLookCount", totalLookCount);

        } else {

            resultMap.put("totalLookCount", 0);

        }

        LookArticleStatisEntity todayTlookArticleStatisInfo = lookArticleInfoService.getTodayLookArticleStatisInfo(Integer.valueOf(userId));

        if (todayTlookArticleStatisInfo != null) {

            resultMap.put("todayLookCount", Optional.ofNullable(todayTlookArticleStatisInfo.getTodayLookCount()).orElse(0));

        } else {

            resultMap.put("todayLookCount", 0);

        }

        resultMap.put("vipStatus", vipStatus);

        //开关设置处理
        WxNotifyMsgSetInfo wxNotifyMsgSetInfo = userInfoService.getUserNotifySetInfo(Integer.parseInt(userId));
        if (wxNotifyMsgSetInfo == null) {
            resultMap.put("notifySwitchStatus", 1);
            resultMap.put("nightDisturbStatus", 1);
        } else {
            resultMap.put("notifySwitchStatus", Optional.ofNullable(wxNotifyMsgSetInfo.getNotifySwitchStatus()).orElse(0));
            resultMap.put("nightDisturbStatus", Optional.ofNullable(wxNotifyMsgSetInfo.getNightDisturbStatus()).orElse(0));
        }

        // 添加访问记录
        this.addAccessRecord(Integer.valueOf(userId),identifying);

        //获取客户页面提示文字
        String promptText = articleInfoService.generateCustomerPagePromptText(Integer.parseInt(userId), totalLookCount);
        resultMap.put("promptText", promptText);

        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 异步添加用户访问记录
     * @param userId
     */
    @Async
    void addAccessRecord(Integer userId,String identifying){
        PageDetailLog log = new PageDetailLog();
        log.setAccessTime(new Date());
        log.setGzhCode(identifying);
        log.setPageName("客户");
        log.setUserId(userId);
        this.connectionInfoService.addAccessRecord(log);
    }

    @PostMapping(value = "/getPlatformBrandAndArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData getPlatformBrandAndArticleTypeInfo() {

        List<ArticleTypeInfo> articleTypeInfo = articleTypeInfoService.getArticleTypeInfo();

        List<Map<String, Object>> platformArticleTypeInfo = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(articleTypeInfo)) {
            articleTypeInfo.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);
                infoMap.put("articleTypeId", info.getId());
                infoMap.put("articleTypeName", info.getArticleTypeName());

                platformArticleTypeInfo.add(infoMap);
            });
        }

        List<BrandInfo> brandInfo = brandInfoService.getBrandInfo();

        List<Map<String, Object>> platformBrandInfo = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(brandInfo)) {
            brandInfo.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);
                infoMap.put("brandId", info.getId());
                infoMap.put("brandName", info.getBrandName());

                platformBrandInfo.add(infoMap);
            });
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleTypeInfo", platformArticleTypeInfo);
        resultMap.put("brandInfo", platformBrandInfo);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/preAddAritcleInfo", produces = "application/json;charset=UTF-8")
    public RespData preAddAritcleInfo(@RequestHeader("userId") String userId, @RequestBody PreAddAritcleInfoReqBean preAddAritcleInfoReqBean) {

        if (preAddAritcleInfoReqBean == null || StringUtils.isBlank(preAddAritcleInfoReqBean.getArticleUrl())) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        String articleUrl = preAddAritcleInfoReqBean.getArticleUrl();

        if (!articleUrl.contains("mp.weixin.qq.com")) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂时只支持微信公众号文章");
            return respData;

        }

        Document document = null;
        try {
            document = Jsoup.connect(articleUrl).get();
        } catch (IOException e) {
            e.printStackTrace();
        }

        ArticleInfo articleInfo = new ArticleInfo();

        String articleTitle = document.title();
        articleInfo.setArticleTitle(articleTitle);

        Elements elements = document.body().select("div#js_content").first().getElementsByTag("p");

        List<ArticleContentInfo> articleContentInfoList = Lists.newArrayList();

        for (Element element : elements) {

            Elements imgEle = element.getElementsByTag("img");
            if (imgEle != null && imgEle.size() > 0) {

                for (Element img : imgEle) {

                    ArticleContentInfo articleContentInfo = new ArticleContentInfo();

                    String imgSrc = img.attr("data-src");

                    String imgType = img.attr("data-type");

                    if (!StringUtils.isEmpty(imgType)) {
                        imgType = "png";
                    }

                    String imgName = UUID.randomUUID().toString() + "." + imgType;

                    if (!StringUtils.isEmpty(imgSrc)) {
                        AliImgUtil.uploadWechatArticleImg(userId, imgSrc, imgName);
                    }

                    String finalImgUrl = SysConstant.ARTICLE_IMG_ACCESS_PREFIX + SysConstant.WX_PN_ARTICLE_IMG_FOLDER_PATH + userId + "/" + imgName;
                    articleContentInfo.setTextType(2);
                    articleContentInfo.setTextContent(finalImgUrl);

                    String articleImgUrl = articleInfo.getArticleImgUrl();
                    if (StringUtils.isBlank(articleImgUrl)) {
                        articleInfo.setArticleImgUrl(finalImgUrl);
                    }

                    articleContentInfoList.add(articleContentInfo);

                }

            }

            Elements videoEle = element.getElementsByTag("iframe");
            if (videoEle != null && videoEle.size() > 0) {

                for (Element video : videoEle) {

                    ArticleContentInfo articleContentInfo = new ArticleContentInfo();
                    articleContentInfo.setTextType(1);
                    articleContentInfo.setTextContent(video.toString());

                    articleContentInfoList.add(articleContentInfo);

                }

            }

            if (imgEle == null || videoEle == null || imgEle.size() == 0 || videoEle.size() == 0) {

                String eleText = element.text();
                if (StringUtils.isNotBlank(eleText)) {
                    ArticleContentInfo articleContentInfo = new ArticleContentInfo();
                    articleContentInfo.setTextType(1);
                    articleContentInfo.setTextContent(eleText);

                    articleContentInfoList.add(articleContentInfo);

                    String articleDesc = Optional.ofNullable(articleInfo.getArticleDesc()).orElse("");
                    if (StringUtils.isBlank(articleDesc) || articleDesc.length() < 40) {

                        if (eleText.length() <= 50) {
                            articleInfo.setArticleDesc(articleDesc + eleText);
                        } else {
                            articleInfo.setArticleDesc(eleText.substring(0, 40));
                        }

                    }
                }

            }

            //文章内容
            String articleContent = JSONObject.toJSONString(articleContentInfoList);
            articleInfo.setArticleContent(articleContent);

        }

        String articleDesc = articleInfo.getArticleDesc();
        if (StringUtils.isBlank(articleDesc)) {
            articleInfo.setArticleDesc(articleTitle);
        }

        articleInfo.setUserId(Integer.valueOf(userId));
        articleInfo.setArticleSource(2);
        articleInfo.setArticleStatus(1);
        articleInfo.setCreateTime(DateUtil.getCurDate());
        articleInfoService.addWechatArticleInfo(articleInfo);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(8);

        UserInfo userInfo = userInfoService.getUserBaseInfo(Integer.valueOf(userId));
        resultMap.put("userId", userInfo.getUserId());
        resultMap.put("nickName", userInfo.getNickName());
        resultMap.put("avatarUrl", userInfo.getAvatarUrl());
        resultMap.put("signature", userInfo.getSignature());

        resultMap.put("articleTitle", articleInfo.getArticleTitle());
        resultMap.put("articleId", articleInfo.getId());
        resultMap.put("articleInfo", articleContentInfoList);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/saveArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData saveArticleInfo(@RequestHeader("userId") String userId, @RequestBody SaveArticleInfoReqBean saveArticleInfoReqBean) {

        if (saveArticleInfoReqBean == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        Integer finalArticleId = saveArticleInfoReqBean.getArticleId();

        int saveType = saveArticleInfoReqBean.getSaveType();
        if (saveType == 1) {
            //保存公众号文章
            ArticleInfo articleInfo = new ArticleInfo();
            articleInfo.setId(saveArticleInfoReqBean.getArticleId());
            articleInfo.setArticleTypeId(saveArticleInfoReqBean.getArticleTypeId());
            articleInfo.setArticleBrandId(saveArticleInfoReqBean.getArticleBrandId());
            articleInfo.setModifyTime(DateUtil.getCurDate());
            articleInfo.setArticleImgUrl(saveArticleInfoReqBean.getArticleImgUrl());
            articleInfoService.modifyWechatArticleInfo(articleInfo);

        } else if (saveType == 2) {

            //保存用户编辑的文章
            Integer articleId = saveArticleInfoReqBean.getArticleId();

            int articleVersionNum = Optional.ofNullable(saveArticleInfoReqBean.getArticleVersionNum()).orElse(1);

            if (articleId != null) {
                //查询文章ID信息，判断是不是用户自己的文章
                Integer articleUserId = articleInfoService.getArticleUserInfo(articleId);

                //没有用户信息，相当于是保存平台文章，则进行添加;否则如果是自己的文章，则进行更新
                if (articleUserId != null && articleUserId.intValue() == Integer.parseInt(userId)) {

                    ArticleInfo articleInfo = new ArticleInfo();
                    articleInfo.setId(articleId);
                    articleInfo.setArticleTitle(saveArticleInfoReqBean.getArticleTitle());
                    articleInfo.setArticleImgUrl(saveArticleInfoReqBean.getArticleImgUrl());
                    articleInfo.setArticleBrandId(saveArticleInfoReqBean.getArticleBrandId());
                    articleInfo.setArticleTypeId(saveArticleInfoReqBean.getArticleTypeId());
                    articleInfo.setVideoHeight(saveArticleInfoReqBean.getVideoHeight());

                    if (articleVersionNum == 1) {
                        articleInfo.setArticleContent(JSONObject.toJSONString(saveArticleInfoReqBean.getArticleContent()));
                    } else {
                        articleInfo.setArticleContent(saveArticleInfoReqBean.getNewArticleContent());
                    }

                    //articleInfo.setArticleContent(AliyunOssClientUtil.clearImgUrlPAR(articleInfo.getArticleContent()));//2012-12-28 hyl，去掉图片中的oss 压缩参数

                    articleInfo.setModifyTime(DateUtil.getCurDate());

                    articleInfoService.modifyUserArticleInfo(articleInfo);

                } else if (articleUserId == null) {

                    ArticleInfo articleInfo = new ArticleInfo();
                    articleInfo.setArticleTitle(saveArticleInfoReqBean.getArticleTitle());
                    articleInfo.setArticleImgUrl(saveArticleInfoReqBean.getArticleImgUrl());
                    articleInfo.setArticleBrandId(saveArticleInfoReqBean.getArticleBrandId());
                    articleInfo.setArticleTypeId(saveArticleInfoReqBean.getArticleTypeId());
                    articleInfo.setVideoHeight(saveArticleInfoReqBean.getVideoHeight());
                    articleInfo.setUserId(Integer.valueOf(userId));
                    articleInfo.setArticleSource(3);
                    articleInfo.setArticleStatus(1);

                    if (articleVersionNum == 1) {
                        articleInfo.setArticleContent(JSONObject.toJSONString(saveArticleInfoReqBean.getArticleContent()));
                    } else {
                        articleInfo.setArticleContent(saveArticleInfoReqBean.getNewArticleContent());
                    }
                    //articleInfo.setArticleContent(AliyunOssClientUtil.clearImgUrlPAR(articleInfo.getArticleContent()));//2012-12-28 hyl，去掉图片中的oss 压缩参数

                    articleInfo.setSpiderProcessStatus(1);
                    articleInfo.setArticleVersionNum(articleVersionNum);
                    articleInfo.setCreateTime(DateUtil.getCurDate());

                    articleInfoService.addUserArticleInfo(articleInfo);

                    finalArticleId = articleInfo.getId();

                }

            }


        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleId", finalArticleId);
        respData.setData(resultMap);

        respData.setMsg("成功");
        return respData;
    }

    /**
     * 获取文章详情
     * 1-平台文章 2-用户文章
     *
     * 1、用户打开平台文章或自己的文章，如果用户设置了该文章类型的广告且广告处于开启状态，则显示广告(包含编辑广告按钮)。否则，显示按钮。
     * 2、用户打开别人(文章所属者)的文章，如果文章所属者设置了该文章类型的广告且广告处于开启状态，则显示广告(不包含编辑广告按钮)。否则，不显示广告和按钮。
     *
     * @param userId
     * @param identifying
     * @param articleDetailInfoReqBean
     * @return
     */
    @PostMapping(value = "/getArticleDetailInfo", produces = "application/json;charset=UTF-8")
    public RespData getArticleDetailInfo(@RequestHeader("userId") String userId,
                                         @RequestHeader("identifying") String identifying,
//                                         @RequestParam Integer articleId,
//                                         @RequestParam("WhV0Ds") String WhV0Ds, //公钥
//                                         @RequestParam(required=false) String shareUserId,
//                                         @RequestParam(required=false) String t
                                         @RequestBody GetArticleDetailInfoReqBean articleDetailInfoReqBean
    ) {

        //log.error("执行getArticleDetailInfo 开始："+DateUtil.getFormatDate("Iyyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        Integer articleId = articleDetailInfoReqBean.getArticleId();
        Integer imgCompress = articleDetailInfoReqBean.getImgCompress();//是否 使用oss参数压缩图片（1 为 是） 2021-12-28 hyl
        String shareUserId = articleDetailInfoReqBean.getShareUserId();
        String t = articleDetailInfoReqBean.getT();

        log.info("[articleId] = {}, [imgCompress] = {}, [shareUserId] = {}, [t] = {},", articleId, imgCompress, shareUserId, t);


        //初始化 WeixinServiceDL start
        WeixinServiceDL weixinService = WeixinServiceMap.getWeixinService(identifying);
        if (weixinService == null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(identifying);
            WeixinServiceMap.putWeixinService(identifying, weixinService);
        }
        //初始化 WeixinServiceDL end

        if (articleId == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        int userIdInt = Integer.parseInt(userId);// 当前用户


        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);
        if (articleInfo == null || articleInfo.getId() == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.ARTICLE_NOT_EXIST);
            respData.setMsg("该文章不存在");
            return respData;
        }


        //20204006 处理二维码 飘动问题
        articleInfo.setArticleContent(articleInfo.getArticleContent().replace("section class=\"qr_code_pc\" style=\"margin", "section class=\"qr_code_pc\" style=\"display:none;margin"));
        //20204006 处理二维码 飘动问题

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(43);
        int isOwn = 1;// 是否属于自己 0：不属于 1-属于
//        int advertDisplayType = 0;// 广告显示类型：0-开关和内容都不显示 1-显示开关 2-显示内容
        int advertDisplayType = 0;// 广告显示类型：0-开关和内容都不显示 1-显示内容
        int tableDisplayType = 0;// 表格显示类型：0-开关和内容都不显示 1-显示开关 2-显示内容
        String advertContent = "";// 广告内容

        Integer articleUserId = articleInfo.getUserId();// 文章所属者

        //如果不存在文章用户ID，则认为是平台文章，此时展示当前用户自己的信息
        if (articleUserId == null) {

            if (StringUtils.isNotBlank(shareUserId) && StringUtils.isNumeric(shareUserId)) {

                articleUserId = Integer.parseInt(shareUserId);
                //20200401 添加邀请按钮设置
                WxNotifyMsgSetInfo userNotifyMsgSetInfo = userInfoService.getUserNotifySetInfo(articleUserId);
                if (userNotifyMsgSetInfo != null) {
                    resultMap.put("inviteSetStatus", userNotifyMsgSetInfo.getInviteSetStatus());
                    resultMap.put("shareSetStatus", userNotifyMsgSetInfo.getShareSetStatus());
                }

            } else {

                articleUserId = Integer.parseInt(userId);

            }


        } else {
            //20200401 添加邀请按钮设置
            WxNotifyMsgSetInfo userNotifyMsgSetInfo = userInfoService.getUserNotifySetInfo(articleUserId);
            if (userNotifyMsgSetInfo != null) {
                resultMap.put("inviteSetStatus", userNotifyMsgSetInfo.getInviteSetStatus());
                resultMap.put("shareSetStatus", userNotifyMsgSetInfo.getShareSetStatus());
            }
        }

        // 如果当前用户不是文章所属者
        if (!userId.equals(articleUserId.toString())) {
            isOwn = 0;
        }

        resultMap.put("isOwn", isOwn);

        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(identifying);
        UserInfo userInfo = userInfoService.getUserMainInfo(articleUserId);
        //文章所有者的用户信息
        Integer autoVipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(userInfo.getUserId())).orElse(0);
        resultMap.put("userId", String.valueOf(userInfo.getUserId()));
        resultMap.put("autoVipStatus", autoVipStatus);
        resultMap.put("cardStyle", autoVipStatus == 0 ? 0 : Optional.ofNullable(userInfoService.getCardStyle(userInfo.getUserId())).orElse(0));
        resultMap.put("nickName", userInfo.getNickName());
        resultMap.put("avatarUrl", userInfo.getAvatarUrl());
        resultMap.put("signature", userInfo.getSignature());

        resultMap.put("qrcodeUrl", userInfo.getQrcodeUrl());
        resultMap.put("telNum", userInfo.getTelNum());

        // List<String> brandPostImageList = new ArrayList<>();
        String billUrl = Optional.ofNullable(userInfo.getBillUrl()).orElse("");

        if (articleInfo != null && articleInfo.getArticleBrandId() != null) {
            UserBrandInfo userBrandInfoDto = new UserBrandInfo();
            userBrandInfoDto.setUserId(articleUserId);
            userBrandInfoDto.setBrandId(articleInfo.getArticleBrandId());

            UserBrandInfo userBrandInfo = userBrandInfoService.queryUserBandPosterImg(userBrandInfoDto);

            if (userBrandInfo != null && userBrandInfo.getBrandPoster() != null && !userBrandInfo.getBrandPoster().trim().equals("")) {
//                String[] brandPosters = userBrandInfo.getBrandPoster().split(",");
//                Collections.addAll(brandPostImageList, brandPosters);
                billUrl = userBrandInfo.getBrandPoster();
            }
        }

        resultMap.put("billUrl", billUrl);

        //获取用户选中的品牌信息(有效微站)
        BrandInfo selectBrandInfo = userBrandInfoService.getUserSelectBrandInfo(articleUserId);
        String userBrandName = "";
        String userTempContent;
        if (selectBrandInfo != null) {
            userBrandName = selectBrandInfo.getBrandName();
            userTempContent = brandInfoService.getBrandInfoTempByBrandId(articleInfo.getArticleBrandId());

            if (userTempContent == null) {
                userTempContent = "";
            }

            //内容里面含有 #BRAND_CONTENT_TEMPLATE# 并且 品牌内容模板不为空
            if ((articleInfo.getArticleContent().contains(SysConstant.BRAND_CONTENT_TEMPLATE))) {
                articleInfo.setArticleContent(articleInfo.getArticleContent().replaceAll(SysConstant.BRAND_CONTENT_TEMPLATE, userTempContent));//内容
            }
        }
        resultMap.put("userBrandName", userBrandName);

        //当前用户关注公众号状态
        int concernStatus = Optional.ofNullable(userInfoService.getUserConcernStatus(Integer.parseInt(userId))).orElse(0);
        resultMap.put("concernStatus", concernStatus);
        resultMap.put("curUserId", userId);

        resultMap.put("articleTitle", articleInfo.getArticleTitle());
        //resultMap.put("articleImgUrl", articleInfo.getArticleImgUrl()+"?"+"");
        resultMap.put("articleId", articleInfo.getId());

        int articleVersionNum = Optional.ofNullable(articleInfo.getArticleVersionNum()).orElse(1);
        if (identifying.equals("test")) {
            articleVersionNum = 1;
        }

        String strArticleContent = articleInfo.getArticleContent();
        String strArticleImgUrl=articleInfo.getArticleImgUrl();
        String enStr1 = "";
        resultMap.put("KNdSnE", enStr1);//密文

        if(imgCompress!=null && imgCompress.equals(1)) {
            strArticleContent = AliyunOssClientUtil.setImgLoadSize(strArticleContent);//2012-12-28 hyl,处理文章中的图片缩放
            strArticleImgUrl=strArticleImgUrl+"?"+SysConstant.OSS_PAR_80_80;//分享图做 oss 压缩
        }

        resultMap.put("articleInfo", strArticleContent);
        resultMap.put("articleImgUrl", strArticleImgUrl);

        resultMap.put("articleSource", Optional.ofNullable(articleInfo.getArticleSource()).orElse(1));

        String articleDesc = Optional.ofNullable(articleInfo.getArticleDesc()).orElse(articleInfo.getArticleTitle());
        if (StringUtils.isBlank(articleDesc)) {
            articleDesc = articleInfo.getArticleTitle();
        }

        resultMap.put("articleDesc", articleDesc);

        resultMap.put("headAdContent", articleInfo.getHeadAdContent());
        resultMap.put("tailAdContent", articleInfo.getTailAdContent());

        resultMap.put("articleVersionNum", articleVersionNum);

        List<ArticleHeadTailTemplateInfo> articleHeadTailTemplateInfoList = articleHeadTailTemplateInfoService.getUserGlobalHtTemplateInfo(articleUserId);
        if (!CollectionUtils.isEmpty(articleHeadTailTemplateInfoList)) {

            articleHeadTailTemplateInfoList.forEach(info -> {

                int htPosition = Optional.ofNullable(info.getHtTemplatePosition()).orElse(1);
                if (htPosition == 1) {
                    resultMap.put("headAdContent", info.getHtTemplateContent());
                    resultMap.put("headAddUrl", info.getHtTemplatePicturePath());
                } else if (htPosition == 2) {
                    resultMap.put("tailAdContent", info.getHtTemplateContent());
                    resultMap.put("tailAddUrl", info.getHtTemplatePicturePath());
                }

            });

        }

        //如果是自己的文章，则以文章本身的头尾为准
        Integer myAArticleUserId = articleInfoService.getArticleUserInfo(articleId);

        /** ljt 20201103 start*/
//        if (myAArticleUserId != null && myAArticleUserId.intValue() == userIdInt) {
        if (myAArticleUserId != null) {
            /** ljt 20201103 end*/

            String headAdContent = articleInfo.getHeadAdContent();
            if (StringUtils.isNotBlank(headAdContent)) {
                resultMap.put("headAdContent", headAdContent);
            }

            String tailAdContent = articleInfo.getTailAdContent();
            if (StringUtils.isNotBlank(tailAdContent)) {
                resultMap.put("tailAdContent", tailAdContent);
            }

            //getArticleDetailInfo?articleId=22222697&shareUserId=1226314&t=2
            if (articleInfo.getId() != null) {
                String headAddUrl = "", tailAddUrl = "";
                BArticleIllustrate bArticleIllustrate = new BArticleIllustrate();
                //头部插入图片
                bArticleIllustrate.setArticleId(articleInfo.getId());
                bArticleIllustrate.setIllustrateType(1);
                BArticleIllustrate bArticleIllustrateVoHead = this.bArticleIllustrateService.queryByEntity(bArticleIllustrate);

                //底部插入图片
                bArticleIllustrate.setIllustrateType(2);
                BArticleIllustrate bArticleIllustrateVoTail = this.bArticleIllustrateService.queryByEntity(bArticleIllustrate);

                if (bArticleIllustrateVoHead != null) {
                    headAddUrl = bArticleIllustrateVoHead.getIllustrateUrl();
                }

                if (bArticleIllustrateVoTail != null) {
                    tailAddUrl = bArticleIllustrateVoTail.getIllustrateUrl();
                }

                resultMap.put("headAddUrl", headAddUrl);
                resultMap.put("tailAddUrl", tailAddUrl);
            }

        }

        resultMap.put("articleTypeId", articleInfo.getArticleTypeId());
        resultMap.put("articleBrandId", articleInfo.getArticleBrandId());

        String rollName = "正能量";//“换成我的”文字滚动
        if (articleInfo.getArticleBrandId() != null && articleInfo.getArticleBrandId() > 0) {
            rollName = brandInfoService.getBrandInfoByBrandId(articleInfo.getArticleBrandId());
        } else if (articleInfo.getArticleTypeId() != null && articleInfo.getArticleTypeId() > 0) {
            rollName = articleTypeInfoService.getTypeInfoByTypeId(articleInfo.getArticleTypeId());
        }
        resultMap.put("rollName", rollName);
        resultMap.put("createTime", DateUtil.getFormatDate( "yyyy-MM-dd HH:mm:ss", articleInfo.getCreateTime()));

        //告知前端用户是否已经分享过文章
        int userShareArticleCount = Optional.ofNullable(articleInfoService.getUserSharedArticleCount(Integer.parseInt(userId))).orElse(0);
        resultMap.put("userShareArticleCount", userShareArticleCount);

        //保存用户的手机系统类型
        try {
            UserInfo userInfoPM = new UserInfo();
            userInfoPM.setUserId(userIdInt);
            userInfoPM.setPhoneModel(articleDetailInfoReqBean.getPhoneModel());
            userInfoService.modifyWxUserInfo(userInfoPM);
        } catch (Exception e) {
        }

        //String douDouPushCode = "@已重置 邀你成为抖音好友；复制这条信息 ##gWF7KprkVe8## 打开【抖音】";  //20210123 暂时屏蔽
        String douDouPushCode = "";
        resultMap.put("douDouPushCode", douDouPushCode);

        lookArticleAsyncTask.modifyArticleReadCount(articleId, t);

        String[] realmArr = {platformSysInfo.getShareDomainUrl()};

        int index = (int) (Math.random() * realmArr.length);
        String mainlink = realmArr[index];

        resultMap.put("mainlink", mainlink);

        /********************************** 文章底部开关 - 开始 **********************************/

        int articleAdvertSwitchStatus = 1;// 文章底部广告开关：0-关闭 1-开启
        int articleTableSwitchStatus = 1;// 文章底部表单开关：0-关闭 1-开启

        // 获取用户文章底部的按钮开启信息
        UserArticleTailSetInfo articleTailSetInfo = articleInfoService.getArticleTailSetInfo(articleUserId, articleId);
        // 查看总开关
        UserArticleTailSwitchSet userArticleTailSwitchSet = userInfoService.getUserArticleTailSwitchSet(articleUserId);

        if (Objects.nonNull(userArticleTailSwitchSet)) {
            articleAdvertSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getAdvertSwitchStatus()).orElse(1);
            articleTableSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getTableSwitchStatus()).orElse(1);
        }

        if (Objects.nonNull(articleTailSetInfo)) {
//            articleAdvertSwitchStatus = Optional.ofNullable(articleTailSetInfo.getArticleAdvertSwitchStatus()).orElse(1);
            articleTableSwitchStatus = Optional.ofNullable(articleTailSetInfo.getArticleTableSwitchStatus()).orElse(1);
        }

//        resultMap.put("articleAdvertSwitchStatus", articleAdvertSwitchStatus);
        resultMap.put("articleTableSwitchStatus", articleTableSwitchStatus);

        /********************************** 文章底部开关 - 结束 **********************************/

        /********************************** 文章底部广告 - 开始 **********************************/

        // 查看用户的该文章类型广告
        ArticleTailAdvertInfo articleTailAdvertInfo = articleTailAdvertInfoService.getAdvertByType(articleUserId, articleInfo.getArticleTypeId());

        // 如果不存在该用户的广告，
        if (Objects.isNull(articleTailAdvertInfo)) {
            // 如果自己的文章没有设置广告，则显示按钮
            if (isOwn == 1) {
                advertDisplayType = 1;
            } else {
                ArticleTailAdvertInfo advertByType = articleTailAdvertInfoService.getAdvertByType(articleUserId, -1);
                if (advertByType != null && articleAdvertSwitchStatus == 1) {// 查看别人的文章，广告开关打开并且设置了默认广告
                    advertDisplayType = 2;
                    advertContent = advertByType.getAdvertContent();
                }
            }
        } else {
            // 如果文章是自己的，显示广告
            // 如果文章不是自己的且广告开关处于打开状态，显示广告
            if (isOwn == 1 || (isOwn == 0 && articleAdvertSwitchStatus == 1)) {
                advertDisplayType = 2;
            }

            if (Objects.nonNull(articleTailAdvertInfo.getAdvertContent())) {
                advertContent = articleTailAdvertInfo.getAdvertContent();
            } else {
                ArticleTailAdvertInfo advertByType = articleTailAdvertInfoService.getAdvertByType(articleUserId, -1);
                advertContent = advertByType == null ? articleTypeInfoService.queryDefaultAdvert() : advertByType.getAdvertContent();
            }
        }

        /*if (Objects.nonNull(articleTailAdvertInfo)) {
            // 如果文章是自己的，显示广告
            // 如果文章不是自己的且广告开关处于打开状态，显示广告
            if (isOwn == 1 || (isOwn == 0 && articleAdvertSwitchStatus == 1)) {
                advertDisplayType = 1;
            }

            if (StringUtils.isNotBlank(articleTailAdvertInfo.getAdvertContent())) {
                advertContent = articleTailAdvertInfo.getAdvertContent();
            }
        }*/

        resultMap.put("advertDisplayType", advertDisplayType);
        resultMap.put("advertContent", advertContent);

        /********************************** 文章底部广告 - 结束 **********************************/

        Integer finalArticleId = articleInfo.getId();

        log.info("[articleInfo] = {}", articleInfo);

        if (StringUtils.isNotBlank(shareUserId)) {// 如果是查看别人的文章
            ArticleInfo info = new ArticleInfo();
            info.setUserId(Integer.valueOf(shareUserId));
            info.setShareArticleSourceId(articleInfo.getId());

            finalArticleId = articleInfoService.getUserPlatformArticleShareStatus(info);
            /*if (finalArticleId.intValue() > 0) {
                articleId = finalArticleId;// 最终文章 ID
            }*/
        }

        log.info("[finalArticleId] = {}", finalArticleId);

        resultMap.put("finalArticleId", finalArticleId);// 最终文章 ID: 1、如果是别人分享的文章，以这个人生成的文章 ID 为准 2、

        /********************************** 文章底部表格 - 开始 **********************************/

        int tableCommitStatus = 0;// 用户文章表单提交状态：0-未提交 1-已提交

        // 前提：如果用户为会员
//        if (userInfo.getVipStatus().equals(1)) {
            // 如果是别人的文章且处于开启状态，则显示内容
            if (isOwn == 0 && articleTableSwitchStatus == 1) {
                tableDisplayType = 2;

                // 获取表单提交状态
                if (StringUtils.isNotBlank(shareUserId)) {

                }
                tableCommitStatus = articleTableInfoService.getUserCommitStatus(userIdInt, finalArticleId);
            }

            // 自己的文章显示开关
            if (isOwn == 1) {
                tableDisplayType = 1;
            }
//        }
        resultMap.put("tableDisplayType", tableDisplayType);
        resultMap.put("tableCommitStatus", tableCommitStatus);

        /********************************** 文章底部表格 - 结束 **********************************/



        //log.error("执行getArticleDetailInfo 结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        // 阅读量
        resultMap.put("articleReadCount", lookArticleInfoService.getArticleReadCount(finalArticleId) + ToolUtil.randomNum(500, 5000));

        // 点赞数
        resultMap.put("articleLikeCount", articleInfoService.getArticleLikeCount(finalArticleId) + ToolUtil.randomNum(500, 5000));

        // 查看数
        resultMap.put("articleLookCount", lookArticleInfoService.getArticleLookCount(finalArticleId) + ToolUtil.randomNum(500, 5000));

        // 点赞状态
        int articleLikeStatus = this.articleInfoService.giveLikeStatusByArticleId(Integer.valueOf(userId), finalArticleId);
        resultMap.put("articleLikeStatus", articleLikeStatus);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getLookDetailLogId", produces = "application/json;charset=UTF-8")
    public RespData getLookDetailLogId(@RequestHeader("userId") String userId,
                                         @RequestHeader("identifying") String identifying,
                                       @RequestBody GetArticleDetailInfoReqBean articleDetailInfoReqBean
    ) throws Exception {
        //log.error("执行getLookDetailLogId 开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        Integer articleId=articleDetailInfoReqBean.getArticleId();
        String shareUserId=articleDetailInfoReqBean.getShareUserId();
        String t=articleDetailInfoReqBean.getT();

        WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(identifying);
        if(weixinService==null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(identifying);
            WeixinServiceMap.putWeixinService(identifying,weixinService);
        }

        if (articleId == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        int userIdInt = Integer.parseInt(userId);

        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);
        if (articleInfo == null || articleInfo.getId() == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.ARTICLE_NOT_EXIST);
            respData.setMsg("该文章不存在");
            return respData;
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(35);

        Integer articleUserId = articleInfo.getUserId();

        //如果不存在文章用户ID，则认为是平台文章，此时展示当前用户自己的信息
        if (articleUserId == null) {

            if (StringUtils.isNotBlank(shareUserId) && StringUtils.isNumeric(shareUserId)) {
                articleUserId = Integer.parseInt(shareUserId);
            } else {
                articleUserId = Integer.parseInt(userId);
            }
        }

        Integer lookArticleLogId = 0;
        if (articleUserId != null && articleUserId.intValue() != userIdInt) {// 查看别人的文章

            LookArticleInfo lookArticleInfo = new LookArticleInfo();
            lookArticleInfo.setUserId(userIdInt);
            lookArticleInfo.setOtherUserId(articleUserId);
            lookArticleInfo.setArticleId(articleId);

            UserInfo lookUserInfo = userInfoService.getUserMainInfo(userIdInt);

            lookArticleLogId = articleInfoService.lookOtherUserArticleSyn(lookArticleInfo, articleInfo, lookUserInfo.getNickName(), t,identifying);

        }

        /* 20210116 start ljt */
        Integer returnLookArticleId = Optional.ofNullable(lookArticleInfoService.returnLookArticleId(lookArticleLogId)).orElse(articleId);
        /* 20210116 end ljt */
        ArticleLookDetailLog articleLookDetailLog=new ArticleLookDetailLog();
        articleLookDetailLog.setArticleId(returnLookArticleId);
        articleLookDetailLog.setUserId(userIdInt);
        articleLookDetailLog.setGzhCode(identifying);
        articleLookDetailLog.setLookTime(new Date());
        articleLookDetailLog.setResourceType(1);
        articleLookDetailLog.setLookArticleLogId(lookArticleLogId);
        articleLookDetailLog.setLookEndTime(new Date());
        articleLookDetailLog.setSpentTime(0);
        int articleLookDetailLogId = Optional.ofNullable(addLookLog(articleLookDetailLog)).orElse(0);

        resultMap.put("articleLookDetailLogId", String.valueOf(articleLookDetailLogId));
        //log.error("执行getLookDetailLogId 结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @Async
    int addLookLog(ArticleLookDetailLog articleLookDetailLog){
        articleLookDetailLogMapper.addArticleLookDetailLog(articleLookDetailLog);
        return articleLookDetailLog.getId();
    }

    @PostMapping(value = "/updateArticleLookDetailLog", produces = "application/json;charset=UTF-8")
    public RespData updateArticleLookDetailLog(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive, @RequestBody ArticleLookDetailLogList articleLookDetailLogList) {
        RespData respData = new RespData();

        List<ArticleLookDetailLog> list = articleLookDetailLogList.getArticleLookDetailLogList();

//        if(list!=null && list.size()>0) {
//            log.error("****updateArticleLookDetailLog:list:" + list.size());
//            if(list.get(0)!=null){
//                log.error("****updateArticleLookDetailLog:list.get(0)：" +list.get(0).getSpentTime()+"_"+ list.get(0).getLookTime()+"_"+ list.get(0).getLookEndTime());
//            }
//        }

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(springProfilesActive) || list == null || list.size() <= 0) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        if (CollectionUtils.isNotEmpty(list)) {
            for (ArticleLookDetailLog info : list) {
                ArticleLookDetailLog e = articleLookDetailLogMapper.getArticleLookDetailLog(info.getId());
                if (e != null) {
                    Date lookEndTime = e.getLookEndTime();
                    Long diff = lookEndTime.getTime() + info.getSpentTime() * 1000;
                    lookEndTime.setTime(diff);

                    ArticleLookDetailLog upDate = new ArticleLookDetailLog();
                    upDate.setId(info.getId());
                    upDate.setLookEndTime(lookEndTime);
                    upDate.setSpentTime(e.getSpentTime() + info.getSpentTime());

                    articleLookDetailLogMapper.updateArticleLookDetailLog(upDate);
                }
            }

        }

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/queryArticleLookDetailLog", produces = "application/json;charset=UTF-8")
    public RespData queryArticleLookDetailLog(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive, @RequestBody LogDateBase logDateBase) {
        RespData respData = new RespData();

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(springProfilesActive) || logDateBase == null || logDateBase.getArticleId() == null || logDateBase.getArticleLookDetailLogId() == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        List<ArticleLookDetailLog> articleLookDetailLogList = articleLookDetailLogMapper.queryArticleLookDetailLog(logDateBase.getArticleId(), springProfilesActive, logDateBase.getArticleLookDetailLogId());

        if (CollectionUtils.isNotEmpty(articleLookDetailLogList)) {
            Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

            resultMap.put("items", articleLookDetailLogList);
            respData.setData(resultMap);
        }

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getUserLookedArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserLookedArticleInfo(@RequestHeader("userId") String userId, @RequestBody GetUserLookedArticleInfoReqBean getUserLookedArticleInfoReqBean) {

        if (getUserLookedArticleInfoReqBean == null || getUserLookedArticleInfoReqBean.getOtherUserId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getUserLookedArticleInfoReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getUserLookedArticleInfoReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        LookArticleInfo lookArticleInfo = new LookArticleInfo();
        lookArticleInfo.setUserId(getUserLookedArticleInfoReqBean.getOtherUserId());
        lookArticleInfo.setOtherUserId(Integer.valueOf(userId));
        PageInfo<CombinedUserLookOtherArticleInfo> userLookOtherArticleInfoPageInfo = articleInfoService.getUserLookOtherArticleInfo(pageNum, pageSize, lookArticleInfo);

        List<CombinedUserLookOtherArticleInfo> combinedUserLookOtherArticleInfoList = userLookOtherArticleInfoPageInfo.getList();

        combinedUserLookOtherArticleInfoList.forEach(info -> {

            int articleCategory = Optional.ofNullable(info.getArticleCategory()).orElse(1);
            if (articleCategory == 2) {

                PunchClockArticleInfo punchClockArticleInfo = userPunchClockInfoService.getPunchClockArticleInfoById(info.getArticleId());

                String formatDate = DateUtil.getFormatDate("yyyy-MM-dd", punchClockArticleInfo.getClockArticleTime());
                String articleTitle = "";
                int clockArticleTimeType = Optional.ofNullable(punchClockArticleInfo.getClockArticleTimeType()).orElse(1);
                if (clockArticleTimeType == 1) {
                    articleTitle = "早安正能量 " + formatDate;
                } else {
                    articleTitle = "晚安正能量 " + formatDate;
                }

                info.setArticleImgUrl(punchClockArticleInfo.getClockArticleThumbnailUrl());
                info.setArticleTitle(articleTitle);
            }

            //作品案例
            if (articleCategory == 3) {
                BDecorationArticles bDecorationArticles = this.bDecorationArticlesService.queryById(info.getArticleId());

                info.setArticleImgUrl(bDecorationArticles.getCoverPlan());
                info.setArticleTitle(bDecorationArticles.getHeadLine());
            }

            //商学院课程
            if (articleCategory == 4) {
                // 查询商学院课程
                BBusinessInfo bBusinessInfoService = this.bBusinessInfoService.queryById(info.getArticleId());

                info.setArticleImgUrl(bBusinessInfoService.getCover());
                info.setArticleTitle(bBusinessInfoService.getTitle());
            }

            // 获客海报
            if (articleCategory == 5) {
                // 查询获客海报
                BPosterInfo posterInfoService = this.bPosterInfoService.queryById(info.getArticleId());

                info.setArticleImgUrl(posterInfoService.getCover());
                info.setArticleTitle("获客海报");
                try {
                    info.setInfoKey(aesEncrypt(info.getArticleId().toString(), SysConstant.KEY));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        });

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        long count = userLookOtherArticleInfoPageInfo.getTotal();
        resultMap.put("count", count);
        resultMap.put("items", combinedUserLookOtherArticleInfoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getPreEditArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getPreEditArticleInfo(@RequestHeader("userId") String userId, @RequestBody GetPreEditArticleInfoReqBean getPreEditArticleInfoReqBean) {

        if (getPreEditArticleInfoReqBean == null || getPreEditArticleInfoReqBean.getArticleId() == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(getPreEditArticleInfoReqBean.getArticleId());

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(15);

        UserInfo userInfo = userInfoService.getUserBaseInfo(Integer.valueOf(userId));

        //当前用户的用户信息
        resultMap.put("userId", userInfo.getUserId());
        resultMap.put("nickName", userInfo.getNickName());
        resultMap.put("avatarUrl", userInfo.getAvatarUrl());
        resultMap.put("signature", userInfo.getSignature());

        //当前用户ID
        resultMap.put("curUserId", userId);

        resultMap.put("articleTitle", articleInfo.getArticleTitle());
        resultMap.put("articleImgUrl", articleInfo.getArticleImgUrl());
        resultMap.put("articleVersionNum", articleInfo.getArticleVersionNum());
        resultMap.put("articleId", articleInfo.getId());

        int articleVersionNum = Optional.ofNullable(articleInfo.getArticleVersionNum()).orElse(1);
        //if (SysConstant.ARTICLE_VERSION_NUM_OF_ORIGINAL_FORMAT == articleVersionNum) {  //20210222 全部都是新版，没有必要判断，这个字段 用作其它业务

            resultMap.put("articleInfo", articleInfo.getArticleContent());

//        } else {
//
//            resultMap.put("articleInfo", JSONObject.parseArray(articleInfo.getArticleContent(), ArticleContentInfo.class));
//
//        }

        resultMap.put("ocsAccessKey", "LTAIW4MTd90Wq32F");
        resultMap.put("ocsAccessSecret", "7Bft5u5eOGRG47zXX8FCUNIzEOyVyP");

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getArticleInfoByArticleBrand", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByArticleBrand(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByArticleBrandReqBean getArticleInfoByArticleBrandReqBean) {

        if (getArticleInfoByArticleBrandReqBean == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

//        Integer pageNum = getArticleInfoByArticleBrandReqBean.getPageNum();
//        if (pageNum == null || pageNum.intValue() <= 0) {
//            pageNum = 1;
//        }

//        Integer pageSize = getArticleInfoByArticleBrandReqBean.getPageSize();
//        if (pageSize == null || pageNum.intValue() <= 0) {
//            pageSize = 10;
//        }

        //PageInfo<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandPageInfo = articleInfoService.getArticleInfoByBrand(pageNum, pageSize, Integer.valueOf(userId));

        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Integer> userBrandIds = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(userSubBrandInfoList)) {

            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });

        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList = Lists.newArrayList();

        if (userBrandIds != null && userBrandIds.size() > 0) {

            //每页固定10条
            Integer pageSize = 10;

            if (userBrandIds.size() == 1) {

                articleInfoByArticleBrandList = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize);

            } else if (userBrandIds.size() == 2) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize / 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), pageSize / 2);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);

            } else if (userBrandIds.size() == 3) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 4);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);

            } else if (userBrandIds.size() == 4) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 2);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_four);

            } else if (userBrandIds.size() == 5) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_five = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(4), 2);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_four);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_five);

            } else {

                articleInfoByArticleBrandList = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize);

            }

            if (!CollectionUtils.isEmpty(articleInfoByArticleBrandList)) {
                articleInfoByArticleBrandList.forEach(info -> {
                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        //long count = articleInfoByArticleBrandPageInfo.getTotal();
        resultMap.put("count", 100000);
        resultMap.put("items", articleInfoByArticleBrandList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getArticleInfoByArticleType", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByArticleType(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByArticleTypeReqBean getArticleInfoByArticleTypeReqBean) {

        if (getArticleInfoByArticleTypeReqBean == null || getArticleInfoByArticleTypeReqBean.getArticleTypeId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getArticleInfoByArticleTypeReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByArticleTypeReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleTypeList = articleInfoService.getArticleInfoByArticleTypeForRand(getArticleInfoByArticleTypeReqBean.getArticleTypeId(), pageSize);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        //long count = articleInfoByArticleTypePageInfo.getTotal();
        resultMap.put("count", 100000);
        resultMap.put("items", articleInfoByArticleTypeList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;


    }

    @PostMapping(value = "/getUserOwnArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserOwnArticleInfo(@RequestHeader("userId") String userId, @RequestBody GetUserOwnArticleInfoReqBean getUserOwnArticleInfoReqBean) {

        if (getUserOwnArticleInfoReqBean == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getUserOwnArticleInfoReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getUserOwnArticleInfoReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        PageInfo<CombinedUserOwnArticleInfo> userOwnArticleInfoPageInfo = articleInfoService.getUserOwnArticleInfo(pageNum, pageSize, Integer.valueOf(userId));

        List<CombinedUserOwnArticleInfo> userOwnArticleInfoList = userOwnArticleInfoPageInfo.getList();

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        long count = userOwnArticleInfoPageInfo.getTotal();
        resultMap.put("count", count);
        resultMap.put("items", userOwnArticleInfoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/removeUserArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData removeUserArticleInfo(@RequestHeader("userId") String userId, @RequestBody RemoveUserArticleInfoReqBean removeUserArticleInfoReqBean) {

        if (removeUserArticleInfoReqBean == null || removeUserArticleInfoReqBean.getArticleIds() == null || StringUtils.isBlank(removeUserArticleInfoReqBean.getArticleIds())) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        String[] articleIds = removeUserArticleInfoReqBean.getArticleIds().split(",");

        if (articleIds == null || articleIds.length == 0) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        for (String i : articleIds) {
            ArticleInfo articleInfo = new ArticleInfo();
            articleInfo.setId(Integer.valueOf(i));
            articleInfo.setUserId(Integer.valueOf(userId));
            articleInfo.setArticleStatus(0);
            articleInfo.setModifyTime(DateUtil.getCurDate());
            articleInfoService.removeUserArticleInfo(articleInfo);

            // 删除分享记录
            addUserShareArticleInfoAsyncTask.deleteByUserIdAndArticleId(Integer.valueOf(userId), Integer.valueOf(i));
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getPlatformRecommendArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getPlatformRecommendArticleInfo(@RequestHeader("userId") String userId, @RequestBody GetPlatformRecommendArticleInfoReqBean getPlatformRecommendArticleInfoReqBean) {
        ArticleInfo articleInfoInDB = null;

        if (getPlatformRecommendArticleInfoReqBean != null && getPlatformRecommendArticleInfoReqBean.getArticleId() != null) {

            //设置分享的文章为用户文章
            Integer articleId = getPlatformRecommendArticleInfoReqBean.getArticleId();

            //文章是否属于当前用户 false-不属于 true-属于
            boolean articleUserStatus = false;

            if (articleId != null) {
                //查询文章ID信息，判断是不是用户自己的文章
                articleInfoInDB = articleInfoService.getArticleDetailInfo(articleId);

                //只有分享出去的文章时平台文章（没有用户信息），才相当于是保存平台文章为自己文章
                if (getPlatformRecommendArticleInfoReqBean.getArticleType().equals(1)  //只有普通文章才处理 20200112 hyl
                        && articleInfoInDB.getUserId() == null && articleInfoInDB.getArticleSource().intValue() == 1) {

                    //查询用户是否已经分享过该文章
                    ArticleInfo queryArticleInfo = new ArticleInfo();
                    queryArticleInfo.setUserId(Integer.parseInt(userId));
                    queryArticleInfo.setShareArticleSourceId(articleId);

                    int articleShareStatus = Optional.ofNullable(articleInfoService.getUserPlatformArticleShareStatus(queryArticleInfo)).orElse(0);
                    if (articleShareStatus == 0) {

                        ArticleInfo articleInfo = new ArticleInfo();
                        articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                        articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                        articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                        articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                        articleInfo.setUserId(Integer.valueOf(userId));
                        articleInfo.setArticleSource(3);
                        articleInfo.setArticleStatus(1);
                        articleInfo.setShareArticleSourceId(articleId);
                        articleInfo.setArticleContent(articleInfoInDB.getArticleContent());
                        articleInfo.setSpiderProcessStatus(1);
                        articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                        articleInfo.setCreateTime(DateUtil.getCurDate());

                        articleInfo.setsType("分享");
                        articleInfo.setResourceType(articleInfoInDB.getResourceType());
                        articleInfo.setVideoFormat(articleInfoInDB.getVideoFormat());
                        articleInfo.setVideoSize(articleInfoInDB.getVideoSize());
                        articleInfo.setVideoUrl(articleInfoInDB.getVideoUrl());
                        articleInfo.setArticleDesc(articleInfoInDB.getArticleDesc());//分享配文
                        articleInfo.setVideoHeight(articleInfoInDB.getVideoHeight());//视频高度

                        articleInfoService.addUserArticleInfo(articleInfo);

                    }

                }

                //如果文章ID等于当前用户文章，说说明是用户自己分享自己的文章
                if (articleInfoInDB != null && articleInfoInDB.getUserId() != null
                        && articleInfoInDB.getUserId().intValue() == Integer.parseInt(userId)) {

                    articleUserStatus = true;

                }

            }


            //分享操作完成之后，增加文章分享数目
            userArticleProcessService.modifyArticleShareCount(articleId);

            //分享操作完成之后，如果用户分享文章数目还是1，说明该用户是第一次分享文章，此时做相应的推送信息处理
            int userShareArticleCount = Optional.ofNullable(articleInfoService.getUserSharedArticleCount(Integer.parseInt(userId))).orElse(0);

            //区分文章类型 1-普通文章 2-早晚安打卡文章
            int articleType = Optional.ofNullable(getPlatformRecommendArticleInfoReqBean.getArticleType()).orElse(0);

            //如果分享的文章是平台文章，并且文章类型为平台普通文章，则进行首次分享文章处理
            if (userShareArticleCount == 1 && articleType == 1 && articleUserStatus == false) {

                WxUserFirstShareArticleInfo wxUserFirstShareArticleInfo = new WxUserFirstShareArticleInfo();
                wxUserFirstShareArticleInfo.setUserId(Integer.parseInt(userId));
                wxUserFirstShareArticleInfo.setArticleId(articleId);
                //定时任务处理这个文章查看推送请求  //20200108 hyl 这里的逻辑不确 暂时屏蔽以下代码
                //redisCacheUtil.setCacheObject("userFirstShareArticleInfo" + userId, JSON.toJSONString(wxUserFirstShareArticleInfo), 600);

            }

            //增加文章分享记录
            addUserShareArticleInfoAsyncTask.addUserShareArticleInfo(Integer.parseInt(userId), articleId, articleType);

        }

        int callType = Optional.ofNullable(getPlatformRecommendArticleInfoReqBean.getCallType()).orElse(2);
        if (callType == 1) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("成功");
            return respData;

        }

        //获取用户关注的品牌
        /*List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Integer> userBrandIds = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(userSubBrandInfoList)) {

            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });

        }

        if (CollectionUtils.isEmpty(userBrandIds)) {
            userBrandIds.add(1);
            userBrandIds.add(2);
        }*/

        List<PlatformRecommendArticleInfo> platformRecommendArticleInfos = Lists.newArrayList();

        //根据品牌获取平台推荐文章
        /*List<PlatformRecommendArticleInfo> platformRecommendArticleInfoByBrand = articleInfoService.getPlatformRecommendArticleInfoByBrand(userBrandIds);

        //根据类型获取平台推荐文章 1-正能量
        List<PlatformRecommendArticleInfo> platformRecommendArticleInfoByTypeOne = articleInfoService.getPlatformRecommendArticleInfoByType(1);

        //根据类型获取平台推荐文章 4-健康
        List<PlatformRecommendArticleInfo> platformRecommendArticleInfoByTypeTwo = articleInfoService.getPlatformRecommendArticleInfoByType(4);*/

        // 获取 4 篇类型文章
        if (articleInfoInDB.getArticleTypeId() != null) {
            platformRecommendArticleInfos.addAll(articleInfoService.getPlatformRecommendArticleInfoByTypeAndRecordSize(articleInfoInDB.getArticleTypeId(), 4));
        }

        //region 2021-10-28 红包

        // 是否显示红包 0-不显示 1-显示
        int showRedPackage = 0;

        //用户当前的分享文章数目
        int userShareArticleCurrentCount = Optional.ofNullable(userShareArticleInfoService.getUserSharedArticleCount(Integer.parseInt(userId))).orElse(0);

        // 用户VIP状态
        Integer userVipStatus = userInfoService.getUserVipStatus(Integer.parseInt(userId));

        // 如果当前用户不是VIP，且分享文章数量是5的倍数，就显示红包
        if (userShareArticleCurrentCount % 5 == 0 && userVipStatus.intValue() == 0) {
            showRedPackage = 1;
        }

        //endregion

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        /*platformRecommendArticleInfos.addAll(platformRecommendArticleInfoByBrand);
        platformRecommendArticleInfos.addAll(platformRecommendArticleInfoByTypeOne);
        platformRecommendArticleInfos.addAll(platformRecommendArticleInfoByTypeTwo);*/

        resultMap.put("recommendArticleInfo", platformRecommendArticleInfos);
        resultMap.put("showRedPackage", showRedPackage);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/setVideoToUserOwn", produces = "application/json;charset=UTF-8")
    public RespData setVideoToUserOwn(@RequestHeader("userId") String userId, @RequestBody SetAtricleToUserOwnReqBean setAtricleToUserOwnReqBean) {

        int finalArticleId = 0;

        if (setAtricleToUserOwnReqBean != null && setAtricleToUserOwnReqBean.getArticleId() != null) {

            //设置分享的文章为用户文章
            Integer articleId = setAtricleToUserOwnReqBean.getArticleId();

            finalArticleId = articleId;

            if (articleId != null) {
                //查询文章ID信息，判断是不是用户自己的文章
                ArticleInfo articleInfoInDB = articleInfoService.getArticleDetailInfo(articleId);

                //只要文章不是自己的，则保存为自己名下的文章
                if (articleInfoInDB.getUserId() == null || articleInfoInDB.getUserId().intValue() != Integer.parseInt(userId)) {

                    //查询用户是否已经分享过该文章
                    ArticleInfo queryArticleInfo = new ArticleInfo();
                    queryArticleInfo.setUserId(Integer.parseInt(userId));
                    queryArticleInfo.setShareArticleSourceId(articleId);

                    Integer articleShareStatus = Optional.ofNullable(articleInfoService.getUserPlatformArticleShareStatus(queryArticleInfo)).orElse(0);

                    ArticleInfo articleInfo = new ArticleInfo();
                    articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                    articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                    articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                    articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                    articleInfo.setUserId(Integer.valueOf(userId));
                    articleInfo.setArticleSource(3);
                    articleInfo.setArticleStatus(1);
                    articleInfo.setShareArticleSourceId(articleId);
                    articleInfo.setArticleContent(articleInfoInDB.getArticleContent());
                    articleInfo.setSpiderProcessStatus(1);
                    articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                    articleInfo.setsType("换成我的");
                    articleInfo.setResourceType(2);//视频
                    articleInfo.setVideoFormat(articleInfoInDB.getVideoFormat());
                    articleInfo.setVideoSize(articleInfoInDB.getVideoSize());
                    articleInfo.setVideoUrl(articleInfoInDB.getVideoUrl());
                    articleInfo.setArticleDesc(articleInfoInDB.getArticleDesc());//分享配文
                    articleInfo.setVideoHeight(articleInfoInDB.getVideoHeight());//视频高度

                    if (articleShareStatus == 0) {
                        articleInfo.setCreateTime(DateUtil.getCurDate());
                        articleInfoService.addUserArticleInfo(articleInfo);
                        finalArticleId = articleInfo.getId();
                    } else {
                        articleInfo.setId(articleShareStatus);
                        articleInfo.setModifyTime(DateUtil.getCurDate());
                        articleInfoService.modifyUserArticleInfo(articleInfo);
                        finalArticleId = articleShareStatus;
                    }
                }
            }
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleId", finalArticleId);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/setAtricleToUserOwn", produces = "application/json;charset=UTF-8")
    public RespData setAtricleToUserOwn(@RequestHeader("userId") String userId, @RequestBody SetAtricleToUserOwnReqBean setAtricleToUserOwnReqBean) {

        int finalArticleId = 0;

        if (setAtricleToUserOwnReqBean != null && setAtricleToUserOwnReqBean.getArticleId() != null) {

            //设置分享的文章为用户文章
            Integer articleId = setAtricleToUserOwnReqBean.getArticleId();

            finalArticleId = articleId;

            if (articleId != null) {
                //查询文章ID信息，判断是不是用户自己的文章
                ArticleInfo articleInfoInDB = articleInfoService.getArticleDetailInfo(articleId);

                //只要文章不是自己的，则保存为自己名下的文章
                if (articleInfoInDB.getUserId() == null || articleInfoInDB.getUserId().intValue() != Integer.parseInt(userId)) {

                    //查询用户是否已经分享过该文章
                    ArticleInfo queryArticleInfo = new ArticleInfo();
                    queryArticleInfo.setUserId(Integer.parseInt(userId));
                    queryArticleInfo.setShareArticleSourceId(articleId);

                    Integer articleShareStatus = Optional.ofNullable(articleInfoService.getUserPlatformArticleShareStatus(queryArticleInfo)).orElse(0);
                    if (articleShareStatus == 0) {

                        ArticleInfo articleInfo = new ArticleInfo();
                        articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                        articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                        articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                        articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                        articleInfo.setArticleDesc(articleInfoInDB.getArticleDesc());
                        articleInfo.setUserId(Integer.valueOf(userId));
                        articleInfo.setArticleSource(3);
                        articleInfo.setArticleStatus(1);
                        articleInfo.setShareArticleSourceId(articleId);
                        articleInfo.setArticleContent(articleInfoInDB.getArticleContent());
                        articleInfo.setSpiderProcessStatus(1);
                        articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                        articleInfo.setCreateTime(DateUtil.getCurDate());
                        articleInfo.setResourceType(1);
                        articleInfo.setsType("换成我的");

                        articleInfoService.addUserArticleInfo(articleInfo);

                        finalArticleId = articleInfo.getId();

                    } else {

                        ArticleInfo articleInfo = new ArticleInfo();
                        articleInfo.setId(articleShareStatus);
                        articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                        articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                        articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                        articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                        articleInfo.setArticleDesc(articleInfoInDB.getArticleDesc());
                        articleInfo.setUserId(Integer.valueOf(userId));
                        articleInfo.setArticleSource(3);
                        articleInfo.setArticleStatus(1);
                        articleInfo.setShareArticleSourceId(articleId);
                        articleInfo.setArticleContent(articleInfoInDB.getArticleContent());
                        articleInfo.setSpiderProcessStatus(1);
                        articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                        articleInfo.setModifyTime(DateUtil.getCurDate());
                        articleInfo.setResourceType(1);
                        articleInfo.setsType("换成我的");

                        articleInfoService.modifyUserArticleInfo(articleInfo);

                        finalArticleId = articleShareStatus;
                    }

                }

            }

        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleId", finalArticleId);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/storeUserArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData storeUserArticleTypeInfo(@RequestHeader("userId") String userId, @RequestBody StoreUserArticleTypeInfoReqBean storeUserArticleTypeInfoReqBean) {

        if (storeUserArticleTypeInfoReqBean == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        if (StringUtils.isBlank(storeUserArticleTypeInfoReqBean.getUserArticleTypeIds())) {

            UserArticleTypeInfo firstUpdateUserArticleTypeInfo = new UserArticleTypeInfo();
            firstUpdateUserArticleTypeInfo.setUserId(Integer.parseInt(userId));
            firstUpdateUserArticleTypeInfo.setEffectiveStatus(0);
            userArticleTypeInfoService.modifyUserArticleTypeEffectiveStatus(firstUpdateUserArticleTypeInfo);

        } else {

            userArticleTypeInfoService.recordUserArticleTypeInfo(Integer.valueOf(userId), storeUserArticleTypeInfoReqBean.getUserArticleTypeIds());

        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getUserArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserArticleTypeInfo(@RequestHeader("userId") String userId) {

        List<CombinedUserArticleTypeInfo> userArticleTypeInfoList = userArticleTypeInfoService.getUserArticleTypeInfo(Integer.valueOf(userId));

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        RespData respData = new RespData();

        resultMap.put("userArticleTypeInfo", userArticleTypeInfoList);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/searchBrandInfo", produces = "application/json;charset=UTF-8")
    public RespData searchBrandInfo(@RequestHeader("userId") String userId, @RequestBody SearchBrandInfoReqBean searchBrandInfoReqBean) {

        if (searchBrandInfoReqBean == null || StringUtils.isBlank(searchBrandInfoReqBean.getSearchBrandName())) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        List<SearchBrandInfo> searchBrandInfoList = brandInfoService.getBrandInfoByBrandName(searchBrandInfoReqBean.getSearchBrandName());

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        RespData respData = new RespData();

        resultMap.put("searchBrandInfo", searchBrandInfoList);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getBrandAndArticleTypeInfo", produces = "application/json;charset=UTF-8")
    public RespData getBrandAndArticleTypeInfo(@RequestHeader("userId") String userId) {

        List<UserBrandCombinedInfo> brandInfo = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Map<String, Object>> platformBrandInfo = Lists.newArrayList();

        List<ArticleTypeInfo> articleTypeInfo = Lists.newArrayList();

        if (!CollectionUtils.isEmpty(brandInfo)) {

            StringBuffer articleTypeIdsSb = new StringBuffer();

            brandInfo.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);

                int brandId = info.getBrandId();
                infoMap.put("brandId", brandId);
                infoMap.put("brandName", info.getBrandName());

                platformBrandInfo.add(infoMap);

                //查询改品牌是否有关联的类型
                String articleTypeIds = articleBrandAndTypeInfoService.getBrandRelatedArticleTypeIds(brandId);
                if (StringUtils.isNotBlank(articleTypeIds)) {
                    articleTypeIdsSb.append(articleTypeIds);
                    articleTypeIdsSb.append(",");
                }

            });

            if (StringUtils.isNotBlank(articleTypeIdsSb) && articleTypeIdsSb.length() > 0) {

                List<String> articleTypeIds = Arrays.asList(articleTypeIdsSb.toString().split(","));

                List<String> distinctArticleTypeIds = articleTypeIds.stream()
                        .distinct().collect(Collectors.toList());

                if (distinctArticleTypeIds.size() > 0) {

                    articleTypeInfo = articleTypeInfoService.getArticleTypeInfoByIds(distinctArticleTypeIds);

                }

            }
        }

        if (CollectionUtils.isEmpty(articleTypeInfo) || articleTypeInfo.size() == 0) {

            articleTypeInfo = articleTypeInfoService.getArticleTypeInfo();

        }

        List<Map<String, Object>> platformArticleTypeInfo = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(articleTypeInfo)) {
            articleTypeInfo.forEach(info -> {
                HashMap<String, Object> infoMap = Maps.newHashMapWithExpectedSize(2);
                infoMap.put("articleTypeId", info.getId());
                infoMap.put("articleTypeName", info.getArticleTypeName());

                platformArticleTypeInfo.add(infoMap);
            });
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleTypeInfo", platformArticleTypeInfo);
        resultMap.put("brandInfo", platformBrandInfo);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/removeNotSuitableArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData removeNotSuitableArticleInfo(@RequestHeader("userId") String userId, @RequestBody RemoveNotSuitableArticleInfoReqBean removeNotSuitableArticleInfoReqBean) {

        if (removeNotSuitableArticleInfoReqBean == null || removeNotSuitableArticleInfoReqBean.getArticleId() == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        if (SysConstant.DEV_BOSS_BIE_USER_ID.equals(userId) || SysConstant.PROD_BOSS_BIE_USER_ID.equals(userId)) {

            articleInfoService.pseudoDeleteArticleInfo(removeNotSuitableArticleInfoReqBean.getArticleId());

        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getRecommendedByArticleId", produces = "application/json;charset=UTF-8")
    public RespData getRecommendedByArticleId(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive, @RequestBody CombinedUserArticleInfoBySpecialSize entity) {
        RespData respData = new RespData();

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(springProfilesActive) || entity == null || entity.getArticleId() == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageSize = entity.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 5;
        }
        // 文章分享人
        int shareUserId = Optional.ofNullable(entity.getShareUserId()).orElse(0);

        // 文章查看人。
        Integer userIdInt = Integer.parseInt(userId);
        // 是否是自己文章,默认不是。
        boolean yourselfArticle = false;

        // 1-品牌文章 2-分类文章
        Integer type = 1;
        // 品牌id 或 分类id
        Integer articleBrandIdOrTypeId = 0;
        String articleBrandNameOrTypeName = "";

        int articleId = entity.getArticleId();

        ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(articleId);
        if (articleInfo == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂无更多");
            return respData;
        }

        // 文章作者。
        int articleInfoUserId = Optional.ofNullable(articleInfo.getUserId()).orElse(0);
        if (userIdInt == articleInfoUserId) {
            yourselfArticle = true;
        }

        if (articleInfoUserId == 0 && userIdInt == shareUserId) {
            yourselfArticle = true;
        }

        if (articleInfoUserId == 0 && shareUserId == 0) {
            yourselfArticle = true;
        }

        // 品牌id
        Integer articleBrandId = Optional.ofNullable(articleInfo.getArticleBrandId()).orElse(0);
        if (articleBrandId > 0) {
            articleBrandIdOrTypeId = articleBrandId;
            articleBrandNameOrTypeName = brandInfoService.getBrandInfoByBrandId(articleBrandIdOrTypeId);
        }

        // 分类id
        Integer articleTypeId = Optional.ofNullable(articleInfo.getArticleTypeId()).orElse(0);
        if (articleTypeId > 0) {
            type = 2;
            articleBrandIdOrTypeId = articleTypeId;
            articleBrandNameOrTypeName = articleTypeInfoService.getTypeInfoByTypeId(articleBrandIdOrTypeId);
        }

        List<CombinedArticleInfoByArticleBrandAndHotValue> resultList = null;
        List<CombinedArticleInfoByArticleBrandAndHotValue> list = new ArrayList<CombinedArticleInfoByArticleBrandAndHotValue>();

        // 不是是自己的，显示作者分享的。
        if (!yourselfArticle) {

            if (articleInfoUserId == 0) {
                articleInfoUserId = shareUserId;
            }

            resultList = articleInfoService.queryUserArticleInfoByUserId(articleInfoUserId, pageSize);

            if (CollectionUtils.isNotEmpty(resultList)) {

                for (CombinedArticleInfoByArticleBrandAndHotValue info : resultList) {

                    String temporaryArticleBrandNameOrTypeName = "";
                    Integer temporaryBrandId = Optional.ofNullable(info.getArticleBrandId()).orElse(0);
                    Integer temporaryTypeId = Optional.ofNullable(info.getArticleTypeId()).orElse(0);
                    if (temporaryBrandId > 0) {
                        temporaryArticleBrandNameOrTypeName = brandInfoService.getBrandInfoByBrandId(temporaryBrandId);
                    }

                    if (temporaryTypeId > 0) {
                        temporaryArticleBrandNameOrTypeName = articleTypeInfoService.getTypeInfoByTypeId(temporaryTypeId);
                    }

                    String articleHotValue = String.valueOf(ToolUtil.randomNum(500, 5000));

                    info.setArticleHotValue(articleHotValue);
                    info.setArticleBrandNameOrTypeName(temporaryArticleBrandNameOrTypeName);

                    // 作者分享不能是本文章
                    if (info.getArticleId() != articleId) {
                        list.add(info);
                    }
                }

            }
        }

        // 系统文章 或者 是自己的 或者 别人只有当前在看的这篇 ，显示热门推荐阅读。
        if (yourselfArticle || list.size() == 0) {
            PageInfo<CombinedArticleInfoByArticleBrandAndHotValue> combinedArticleInfoByArticleBrandAndHotValue = articleInfoService.getArticleByBrandIdOrTypeId(1, pageSize, type, articleBrandIdOrTypeId);
            resultList = combinedArticleInfoByArticleBrandAndHotValue.getList();

            if (CollectionUtils.isNotEmpty(resultList)) {
                String finalArticleBrandNameOrTypeName = articleBrandNameOrTypeName;

                for (CombinedArticleInfoByArticleBrandAndHotValue info : resultList) {

                    String articleHotValue = String.valueOf(ToolUtil.randomNum(500, 5000));
                    info.setArticleHotValue(articleHotValue);
                    info.setArticleBrandNameOrTypeName(finalArticleBrandNameOrTypeName);

                    // 作者分享不能是本文章
                    if (info.getArticleId() != articleId) {
                        list.add(info);
                    }
                }
            }

            yourselfArticle = true;
        }

        if (list.size() == 5) {
            list.remove(4);
        }

        Integer shareSetStatus = 1;
        if (shareUserId != 0) {
            WxNotifyMsgSetInfo userNotifyMsgSetInfo = userInfoService.getUserNotifySetInfo(shareUserId);
            if (userNotifyMsgSetInfo != null) {
                shareSetStatus = userNotifyMsgSetInfo.getShareSetStatus();
            }
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);
        resultMap.put("articleInfo", list);
        resultMap.put("yourselfArticle", yourselfArticle);
        resultMap.put("shareSetStatus", shareSetStatus);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getUserAssociatedInfoShowInArticleTail", produces = "application/json;charset=UTF-8")
    public RespData getUserAssociatedInfoShowInArticleTail(@RequestHeader("userId") String userId, @RequestBody GetUserAssociatedInfoShowInArticleTailReqBean getUserAssociatedInfoShowInArticleTailReqBean) {

        if (getUserAssociatedInfoShowInArticleTailReqBean == null) {

            getUserAssociatedInfoShowInArticleTailReqBean = new GetUserAssociatedInfoShowInArticleTailReqBean();

        }

        if (StringUtils.isBlank(getUserAssociatedInfoShowInArticleTailReqBean.getOtherUserId())) {
            getUserAssociatedInfoShowInArticleTailReqBean.setOtherUserId(userId);
        }

        //获取前2篇文章
        Integer otherUserId = Integer.valueOf(getUserAssociatedInfoShowInArticleTailReqBean.getOtherUserId());
        List<CombinedUserArticleInfoBySpecialSize> userArticleInfoBySpecialSizeList = articleInfoService.getUserArticleInfoBySpecialSize(otherUserId, 2);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);
        resultMap.put("articleInfo", userArticleInfoBySpecialSizeList);

        //获取前2个商品信息
        BrandInfo selectBrandInfo = userBrandInfoService.getUserSelectBrandInfo(otherUserId);
        Integer brandId = null;
        if (selectBrandInfo != null) {
            brandId = selectBrandInfo.getId();
        }

        List<UserCommodityInfo> userCommodityInfoList = userCommodityInfoService.getUserCommodityInfoBySpecialSize(otherUserId, brandId,2);
        resultMap.put("commodityInfo", userCommodityInfoList);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getUserArticleHtTemplateInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserArticleHtTemplateInfo(@RequestHeader("userId") String userId) {

        List<ArticleHeadTailTemplateInfo> articleHeadTailTemplateInfoList = articleHeadTailTemplateInfoService.getUserHtTemplateInfo(Integer.parseInt(userId));

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("articleHtTemplateInfo", articleHeadTailTemplateInfoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/plugInArticleHtAdInfo", produces = "application/json;charset=UTF-8")
    public RespData plugInArticleHtAdInfo(@RequestHeader("userId") String userId, @RequestBody PlugInArticleHtAdInfoReqBean plugInArticleHtAdInfoReqBean) {


        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        if (plugInArticleHtAdInfoReqBean == null || plugInArticleHtAdInfoReqBean.getArticleId() == null) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        Integer articleId = plugInArticleHtAdInfoReqBean.getArticleId();

        int finalArticleId = articleId;
        int flag = 0;
        int ttTemplatePosition = Optional.ofNullable(plugInArticleHtAdInfoReqBean.getHtTemplatePosition()).orElse(1);

        if (articleId != null) {
            //查询文章ID信息，判断是不是用户自己的文章，并且是模板应用于本篇文章，则将文章添加为自己的文章
            ArticleInfo articleInfoInDB = articleInfoService.getArticleDetailInfo(articleId);

            if (articleInfoInDB.getUserId() == null || articleInfoInDB.getUserId().intValue() != Integer.parseInt(userId)) {

                //如果不是自己的文章，且没有将文章应用于所有，则将该文章保存为自己的文章
                int applyToAllArticleStatus = Optional.ofNullable(plugInArticleHtAdInfoReqBean.getApplyToAllArticleStatus()).orElse(0);

                if (applyToAllArticleStatus == 0) {

                    ArticleInfo articleInfo = new ArticleInfo();
                    articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                    articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                    articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                    articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                    articleInfo.setUserId(Integer.valueOf(userId));
                    articleInfo.setArticleSource(3);
                    articleInfo.setArticleStatus(1);

                    if (ttTemplatePosition == 1) {
                        articleInfo.setHeadAdContent(plugInArticleHtAdInfoReqBean.getHtTemplateContent());
                    } else if (ttTemplatePosition == 2) {
                        articleInfo.setTailAdContent(plugInArticleHtAdInfoReqBean.getHtTemplateContent());
                    }

                    articleInfo.setSpiderProcessStatus(1);
                    articleInfo.setShareArticleSourceId(articleId);
                    articleInfo.setArticleContent(articleInfoInDB.getArticleContent());

                    articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                    articleInfo.setCreateTime(DateUtil.getCurDate());

                    int articleInfoId = articleInfoService.addUserArticleInfo(articleInfo);

                    finalArticleId = articleInfoId;

                    flag = 1;
                }


            } else {

                //如果文章是自己的，则不管是否应用于所有，都只修改当前文章的首尾
                ArticleInfo articleInfo = new ArticleInfo();
                articleInfo.setId(articleId);
                articleInfo.setArticleTitle(articleInfoInDB.getArticleTitle());
                articleInfo.setArticleImgUrl(articleInfoInDB.getArticleImgUrl());
                articleInfo.setArticleBrandId(articleInfoInDB.getArticleBrandId());
                articleInfo.setArticleTypeId(articleInfoInDB.getArticleTypeId());
                articleInfo.setUserId(Integer.valueOf(userId));
                articleInfo.setArticleSource(3);
                articleInfo.setArticleStatus(1);
                articleInfo.setArticleContent(articleInfoInDB.getArticleContent());

                if (ttTemplatePosition == 1) {
                    articleInfo.setHeadAdContent(plugInArticleHtAdInfoReqBean.getHtTemplateContent());
                } else if (ttTemplatePosition == 2) {
                    articleInfo.setTailAdContent(plugInArticleHtAdInfoReqBean.getHtTemplateContent());
                }

                articleInfo.setArticleVersionNum(articleInfoInDB.getArticleVersionNum());
                articleInfo.setModifyTime(DateUtil.getCurDate());

                articleInfoService.modifyUserArticleInfo(articleInfo);

                finalArticleId = articleInfo.getId();

                flag = 1;
            }

        }


        //20201019 ljt 添加文章广告图片 start
        if(flag == 1) {
            ArticleInfo articleInfoForUserId = articleInfoService.getArticleDetailByInfo(finalArticleId);
//            ArticleInfo articleInfoForUserId = articleInfoService.getArticleDetailInfo(finalArticleId);
            //查询文章ID信息，判断是不是用户自己的文章
            if (articleInfoForUserId.getUserId() != null && articleInfoForUserId.getUserId().intValue() == Integer.parseInt(userId)) {
                BArticleIllustrate bArticleIllustrate = new BArticleIllustrate();

                bArticleIllustrate.setArticleId(finalArticleId);//广告海报对应文章Id
                bArticleIllustrate.setIllustrateType(ttTemplatePosition);//模板位置 1-头部 2-尾部

                List<BArticleIllustrate> bArticleIllustrateList = this.bArticleIllustrateService.queryAll(bArticleIllustrate);

                //先删除广告海报
                if (CollectionUtils.isNotEmpty(bArticleIllustrateList)) {
                    bArticleIllustrateList.forEach(info -> {
                        this.bArticleIllustrateService.deleteById(info.getId());
                    });
                }

                BArticleIllustrate bArticleIllustrateVo = new BArticleIllustrate();
                bArticleIllustrateVo.setArticleId(finalArticleId);//广告海报对应文章Id
                bArticleIllustrateVo.setIllustrateUrl(plugInArticleHtAdInfoReqBean.getIllustrateUrl());//广告海报插入图片Url
                bArticleIllustrateVo.setIllustrateType(ttTemplatePosition);//模板位置 1-头部 2-尾部
                bArticleIllustrateVo.setCreateTime(new Date());//创建时间
                bArticleIllustrateVo.setUpdateTime(new Date());//更新时间

                //再添加广告海报
                BArticleIllustrate bArticleIllustrateService = this.bArticleIllustrateService.insert(bArticleIllustrateVo);

                resultMap.put("bArticleIllustrateId", bArticleIllustrateService.getId());
            }
        }
        //20201019 ljt 添加文章广告图片 end

        //首尾模板信息处理
        articleHeadTailTemplateInfoService.handleUserHtTemplateInfo(Integer.parseInt(userId), plugInArticleHtAdInfoReqBean);

        resultMap.put("articleId", finalArticleId);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/removeUserHtTemplateInfo", produces = "application/json;charset=UTF-8")
    public RespData removeUserHtTemplateInfo(@RequestHeader("userId") String userId, @RequestBody RemoveUserHtTemplateInfoReqBean removeUserHtTemplateInfoReqBean) {

        if (removeUserHtTemplateInfoReqBean == null || removeUserHtTemplateInfoReqBean.getHtTemplateId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        articleHeadTailTemplateInfoService.removeUserHtTemplateInfo(Integer.parseInt(userId), removeUserHtTemplateInfoReqBean.getHtTemplateId());

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    /**yl 20200505
     * 查询关注的视频
     * @param userId
     * @param getUserSubArticleInfoReqBean
     * @return
     */
    @PostMapping(value = "/getLikeVideos", produces = "application/json;charset=UTF-8")
    public RespData getLikeVideos(@RequestHeader("userId") String userId, @RequestBody GetUserSubArticleInfoReqBean getUserSubArticleInfoReqBean){
        // 分页相关
        Integer pageNum = 1;
        Integer pageSize = 10;
        if (null !=getUserSubArticleInfoReqBean.getPageNum()){
            pageNum = getUserSubArticleInfoReqBean.getPageNum();
        }
        if (null != getUserSubArticleInfoReqBean.getPageSize()){
            pageSize = getUserSubArticleInfoReqBean.getPageSize();
        }

        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
        // 关注的品牌id集合
        List<Integer> userBrandIds = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(userSubBrandInfoList)) {
            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });
        }
        // 关注的类型id集合
        List<Integer> userConcernArticleTypeIds = this.connectionInfoService.getUserAttentionArticleTypeInfo(Integer.valueOf(userId));

        if (CollectionUtils.isEmpty(userConcernArticleTypeIds)) {
            userConcernArticleTypeIds = userArticleTypeInfoService.getUserConcernArticleTypeInfo(Integer.parseInt(userId));
            if (userConcernArticleTypeIds == null) {
                userConcernArticleTypeIds = Lists.newArrayList();
            }

            userConcernArticleTypeIds.add(1);

        }
        PageInfo pageInfo = articleInfoService.selectArticleByArticleTypeAndBrandId(userConcernArticleTypeIds, userBrandIds, pageNum, pageSize);
        if (null == pageInfo){
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂无数据");
            return respData;
        }

        List<ArticleInfo> collect = pageInfo.getList();
        List<ArticleInfo> list = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(collect)) {
            list = collect.stream().map(info -> {

                /* ljt 20210130 热度伪造 start*/
                info.setArticleHotValue(ToolUtil.setArticleHotValue(info.getArticleHotValue()));
                /* ljt 20210130 热度伪造 end*/

                return info;
            }).collect(Collectors.toList());
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("msg", pageInfo.isIsLastPage());
        resultMap.put("items",list);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 热文
     * @param userId
     * @param identifying
     * @param getUserSubArticleInfoReqBean
     * @return
     */
    @PostMapping(value = "/getUserSubArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserSubArticleInfo(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying, @RequestBody GetUserSubArticleInfoReqBean getUserSubArticleInfoReqBean) {
        /*ljt 20201027 start*/
        //金钻云公众号标识（prodjzyxt）
//        if(identifying != null && "prodjzyxt".equals(identifying)){
        if(identifying != null){// 教培项目
            RespData respData = new RespData();
            Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);

            Integer pageNum = getUserSubArticleInfoReqBean.getPageNum();
            if (pageNum == null || pageNum.intValue() <= 0) {
                pageNum = 1;
            }

            Integer pageSize = getUserSubArticleInfoReqBean.getPageSize();
            if (pageSize == null || pageNum.intValue() <= 0) {
                pageSize = 10;
            }

            // 获取用户分类信息
            UserRelateArticleTypeInfo userRelateArticleTypeInfo = userRelateArticleTypeInfoService.getUserRelateArticleTypeInfo(Integer.parseInt(userId));

            List<Integer> integerList = new ArrayList<Integer>();
            if (Objects.nonNull(userRelateArticleTypeInfo) && StringUtils.isNotBlank(userRelateArticleTypeInfo.getArticleTypeIds())) {
                // 金钻云公众号分类id
                String articleTypeIds = userRelateArticleTypeInfo.getArticleTypeIds();

                // 通过遍历
                String[] strings = articleTypeIds.split(",");
                for (String string : strings) {
                    Integer i = null;
                    // 先对String判空
                    if(StringUtils.isNotBlank(string)){
                        i = Integer.valueOf(string);
                        integerList.add(i);
                    }
                }
            }

            // 屏蔽于20201028
            // List<Integer> integerList = userArticleTypeInfoService.getUserConcernArticleTypeInfo(Integer.parseInt(userId));

            if (CollectionUtils.isEmpty(integerList)) {
                if (integerList == null) {
                    integerList = Lists.newArrayList();
                }
                integerList.add(1);// 财经
                integerList.add(8);// 正能量
                integerList.add(9);// 健康养生
            }

            //根据用户关注的文章类型id倒序查询文章信息
            PageInfo<CombinedArticleInfoByArticleBrand> pageInfo = this.articleInfoService.selectAllByLimit(pageNum, pageSize, integerList);

            if (null == pageInfo) {
                respData.setCode(ReturnCode.CLIENT_ERROR);
                respData.setMsg("暂无数据");
                return respData;
            }

            List<CombinedArticleInfoByArticleBrand> queryAllByLimitDto = pageInfo.getList();
            if (CollectionUtils.isNotEmpty(queryAllByLimitDto)) {
                List<CombinedArticleInfoByArticleBrandAndHotValue> collect = queryAllByLimitDto.stream().map(info -> {

                    CombinedArticleInfoByArticleBrandAndHotValue temporary = new CombinedArticleInfoByArticleBrandAndHotValue();
                    String articleHotValue = String.valueOf(new Random().nextInt(5000)%(5000-500+1) + 500);

                    ArticleTypeInfo articleTypeInfo = this.articleTypeInfoMapper.selectBrandNameAndBrandHeadByTypeId(info.getArticleTypeId());
                    String typeName = articleTypeInfo.getArticleTypeName();

                    temporary.setArticleId(info.getArticleId());
                    temporary.setArticleTitle(info.getArticleTitle());
                    temporary.setArticleImgUrl(info.getArticleImgUrl());
                    temporary.setArticleTypeId(info.getArticleTypeId());
                    temporary.setResourceType(info.getResourceType());
                    temporary.setArticleTypeName(typeName);
                    temporary.setArticleHotValue(articleHotValue);
                    temporary.setArticleVersionNum(info.getArticleVersionNum());

                    return temporary;
                }).collect(Collectors.toList());

                long count = pageInfo.getTotal();
                resultMap.put("count", count);
                resultMap.put("msg", pageInfo.isIsLastPage());
                resultMap.put("items", collect);
                respData.setData(resultMap);
                respData.setCode(ReturnCode.NORMAL_SUCC);
                respData.setMsg("成功");
                return respData;
            }

            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }
        /*ljt 20201027 end*/

        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Integer> userBrandIds = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(userSubBrandInfoList)) {

            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });
        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList = Lists.newArrayList();

        // 20200202 ljt start
        if (identifying != null && (!identifying.equals("test")
//                || identifying.equals("back_zkt")
//                || identifying.equals("prodyysck")
//                || identifying.equals("prodyyzs")
//                || identifying.equals("prodqkb")
//                || identifying.equals("prodhkbw")
//                || identifying.equals("prodbst")
        )) {
            if (userBrandIds != null && userBrandIds.size() > 0) {
                articleInfoByArticleBrandList = getBalaBala(userBrandIds, userId);
            }

            List<CombinedArticleInfoByArticleBrandAndHotValue> articleInfoByArticleBrandListAndHotValue = Lists.newArrayList();

            if(CollectionUtils.isNotEmpty(articleInfoByArticleBrandList)){
                for (CombinedArticleInfoByArticleBrand value : articleInfoByArticleBrandList){
                    CombinedArticleInfoByArticleBrandAndHotValue info = new CombinedArticleInfoByArticleBrandAndHotValue();

                    String temporaryArticleBrandNameOrTypeName = "";
                    Integer temporaryBrandId = Optional.ofNullable(value.getArticleBrandId()).orElse(0);
                    Integer temporaryTypeId = Optional.ofNullable(value.getArticleTypeId()).orElse(0);
                    if (temporaryBrandId > 0) {
                        temporaryArticleBrandNameOrTypeName = brandInfoService.getBrandInfoByBrandId(temporaryBrandId);
                    }

                    if (temporaryTypeId > 0) {
                        temporaryArticleBrandNameOrTypeName = articleTypeInfoService.getTypeInfoByTypeId(temporaryTypeId);
                    }

                    String articleHotValue = String.valueOf(ToolUtil.randomNum(500, 5000));

                    info.setArticleId(value.getArticleId());
                    info.setArticleTitle(value.getArticleTitle());
                    info.setArticleImgUrl(value.getArticleImgUrl());
                    info.setArticleBrandId(value.getArticleBrandId());
                    info.setArticleTypeId(value.getArticleTypeId());
                    info.setResourceType(value.getResourceType());
                    info.setArticleHotValue(articleHotValue);

                    info.setArticleBrandName(temporaryArticleBrandNameOrTypeName);
                    info.setArticleTypeName(temporaryArticleBrandNameOrTypeName);
                    info.setArticleVersionNum(value.getArticleVersionNum());

                    articleInfoByArticleBrandListAndHotValue.add(info);
                }

                RespData respData = new RespData();
                respData.setCode(ReturnCode.NORMAL_SUCC);

                Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

                resultMap.put("count", 100000);
                resultMap.put("items", articleInfoByArticleBrandListAndHotValue);
                respData.setData(resultMap);
                respData.setMsg("成功");
                return respData;
            }

            RespData respData = new RespData();
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }

        if (userBrandIds != null && userBrandIds.size() > 0) {

            //每页固定10条
            Integer pageSize = 5;

            if (userBrandIds.size() == 1) {

                articleInfoByArticleBrandList = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize);

            } else if (userBrandIds.size() == 2) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize / 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), pageSize / 2);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);

            } else if (userBrandIds.size() == 3) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 1);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);

            } else if (userBrandIds.size() == 4) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 1);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_four);

            } else if (userBrandIds.size() == 5) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 1);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_five = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(4), 1);

                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_four);
                articleInfoByArticleBrandList.addAll(articleInfoByArticleBrandList_five);

            }

            if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandList)) {
                articleInfoByArticleBrandList.forEach(info -> {
                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

        }

        List<Integer> userConcernArticleTypeIds = userArticleTypeInfoService.getUserConcernArticleTypeInfo(Integer.parseInt(userId));

        if (CollectionUtils.isEmpty(userConcernArticleTypeIds)) {

            if (userConcernArticleTypeIds == null) {
                userConcernArticleTypeIds = Lists.newArrayList();

            }

            userConcernArticleTypeIds.add(1);

        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleTypeList = articleInfoService.getArticleInfoByUserConcernArticleTypeForRand(userConcernArticleTypeIds, 15);

        List<CombinedArticleInfoByArticleBrandAndHotValue> articleInfoByArticleBrandListAndHotValue = Lists.newArrayList();

        if (CollectionUtils.isNotEmpty(articleInfoByArticleTypeList)) {

            articleInfoByArticleBrandList.addAll(articleInfoByArticleTypeList);

            for(int i = 0; i < articleInfoByArticleBrandList.size(); i++){
                String articleHotValue = String.valueOf(new Random().nextInt(5000)%(5000-500+1) + 500);
                CombinedArticleInfoByArticleBrandAndHotValue info=new CombinedArticleInfoByArticleBrandAndHotValue();
                CombinedArticleInfoByArticleBrand combinedArticleInfoByArticleBrand=articleInfoByArticleBrandList.get(i);

                if(combinedArticleInfoByArticleBrand.getArticleTypeId()!=null) {
                    ArticleTypeInfo articleTypeInfo = this.articleTypeInfoMapper.selectBrandNameAndBrandHeadByTypeId(combinedArticleInfoByArticleBrand.getArticleTypeId());
                    String typeName = articleTypeInfo.getArticleTypeName();
                    info.setArticleTypeName(typeName);
                }

                info.setArticleId(combinedArticleInfoByArticleBrand.getArticleId());
                info.setArticleTitle(combinedArticleInfoByArticleBrand.getArticleTitle());
                info.setArticleImgUrl(combinedArticleInfoByArticleBrand.getArticleImgUrl());
                info.setArticleBrandName(combinedArticleInfoByArticleBrand.getArticleBrandName());
                info.setArticleBrandId(combinedArticleInfoByArticleBrand.getArticleBrandId());
                info.setArticleTypeId(combinedArticleInfoByArticleBrand.getArticleTypeId());

                info.setResourceType(combinedArticleInfoByArticleBrand.getResourceType());
                info.setArticleHotValue(articleHotValue);
                info.setArticleVersionNum(combinedArticleInfoByArticleBrand.getArticleVersionNum());

                articleInfoByArticleBrandListAndHotValue.add(info);
            }

            RespData respData = new RespData();
            respData.setCode(ReturnCode.NORMAL_SUCC);

            Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

            resultMap.put("count", 100000);
            resultMap.put("items", articleInfoByArticleBrandListAndHotValue);
            respData.setData(resultMap);
            respData.setMsg("成功");
            return respData;

        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("暂无数据");
        return respData;

    }

    @PostMapping(value = "/getPlatformArticleInfoBySingleArticleBrand", produces = "application/json;charset=UTF-8")
    public RespData getPlatformArticleInfoBySingleArticleBrand(@RequestHeader("userId") String userId, @RequestBody GetPlatformArticleInfoBySingleArticleBrandReqBean getPlatformArticleInfoBySingleArticleBrandReqBean) {

        if (getPlatformArticleInfoBySingleArticleBrandReqBean == null || getPlatformArticleInfoBySingleArticleBrandReqBean.getArticleBrandId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

//        Integer pageNum = getArticleInfoByArticleBrandReqBean.getPageNum();
//        if (pageNum == null || pageNum.intValue() <= 0) {
//            pageNum = 1;
//        }

//        Integer pageSize = getArticleInfoByArticleBrandReqBean.getPageSize();
//        if (pageSize == null || pageNum.intValue() <= 0) {
//            pageSize = 10;
//        }

        //PageInfo<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandPageInfo = articleInfoService.getArticleInfoByBrand(pageNum, pageSize, Integer.valueOf(userId));

        int reqArticleBrandId = Optional.ofNullable(getPlatformArticleInfoBySingleArticleBrandReqBean.getArticleBrandId()).orElse(0);
        if (reqArticleBrandId == 0) {
            reqArticleBrandId = 1;
        }

        int pageSize = 10;

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList = articleInfoService.getArticleInfoByBrandForRand(reqArticleBrandId, pageSize);

        if (!CollectionUtils.isEmpty(articleInfoByArticleBrandList)) {
            articleInfoByArticleBrandList.forEach(info -> {
                Integer articleBrandId = info.getArticleBrandId();
                if (articleBrandId != null) {
                    String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                    info.setArticleBrandName(articleBrandName);
                }
            });
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        //long count = articleInfoByArticleBrandPageInfo.getTotal();
        resultMap.put("count", 100000);
        resultMap.put("items", articleInfoByArticleBrandList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getArticleInfoByArticleTypeForHotScore", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByArticleTypeForHotScore(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive, @RequestBody GetArticleInfoByArticleTypeForHotScoreReqBean getArticleInfoByArticleTypeForHotScoreReqBean) {

        if (getArticleInfoByArticleTypeForHotScoreReqBean == null || getArticleInfoByArticleTypeForHotScoreReqBean.getArticleTypeId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getArticleInfoByArticleTypeForHotScoreReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByArticleTypeForHotScoreReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        //if(pageNum.equals(1)) {
            //articleInfoService.insertArticleInfoByArticleType(getArticleInfoByArticleTypeForHotScoreReqBean.getArticleTypeId(),springProfilesActive);
        //}

        PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.getArticleInfoByArticleTypeForHotScore(pageNum, pageSize, getArticleInfoByArticleTypeForHotScoreReqBean.getArticleTypeId(), null,springProfilesActive);

        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(4);

        List<ArticleListShowInfo> articleListShowInfoList = articleListShowInfoPageInfo.getList();
        int listSize = CollectionUtils.isNotEmpty(articleListShowInfoList) ? articleListShowInfoList.size() : 0;
        if (listSize >= pageSize) {
            resultMap.put("continueQueryFlag", 1);
        } else {
            resultMap.put("continueQueryFlag", 0);
        }

        long count = articleListShowInfoPageInfo.getTotal();

        /** ljt 20201031 start 给list添加分类名*/
        //分类名称
        ArticleTypeInfo articleTypeInfo = this.articleTypeInfoService.selectBrandNameAndBrandHeadByTypeId(getArticleInfoByArticleTypeForHotScoreReqBean.getArticleTypeId());
//      这里 articleTypeInfoService 用成了 articleTypeInfoMapper， ljt 20201112 修改对了
//      ArticleTypeInfo articleTypeInfo = this.articleTypeInfoMapper.selectBrandNameAndBrandHeadByTypeId(getArticleInfoByArticleTypeForHotScoreReqBean.getArticleTypeId());
        String typeName = articleTypeInfo.getArticleTypeName();

        /** ljt 20201112 start 判空 */
        if (null == articleListShowInfoPageInfo.getList() || articleListShowInfoPageInfo.getList().size() <= 0) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂无数据");
            return respData;
        }
        /** ljt 20201112 end 判空 */

        if (CollectionUtils.isNotEmpty(articleListShowInfoList) && typeName != null) {

            List<ArticleListShowInfo> collect = articleListShowInfoList.stream().map(info -> {

                /* ljt 20210130 热度伪造 start*/
                info.setArticleHotValue(ToolUtil.setArticleHotValue(info.getArticleHotValue()));
                /* ljt 20210130 热度伪造 end*/

                info.setArticleTypeName(typeName);

                return info;
            }).collect(Collectors.toList());

            resultMap.put("msg", count);
            resultMap.put("items", collect);
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setData(resultMap);
            respData.setMsg("成功");
            return respData;

        }
        /** ljt 20201031 start 给list添加分类名*/

        resultMap.put("count", count);
        resultMap.put("items", articleListShowInfoList);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    /**
     * 如果该品牌没有文章了，那么就找关联品牌文章，如果没有关联分类文章
     * @param userId
     * @param springProfilesActive
     * @param e
     * @return
     */
    @PostMapping(value = "/getLinkArticle", produces = "application/json;charset=UTF-8")
    public RespData getLinkArticle(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive, @RequestBody GetArticleInfoByArticleBrandForHotScoreReqBean e) {

        List<ArticleListShowInfo> info =  articleInfoService.getLinkArticle(e.getArticleBrandId());

        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(6);
        resultMap.put("items", info);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/getArticleInfoByArticleBrandForHotScore", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByArticleBrandForHotScore(@RequestHeader("userId") String userId, @RequestHeader("identifying") String springProfilesActive,@RequestBody GetArticleInfoByArticleBrandForHotScoreReqBean getArticleInfoByArticleBrandForHotScoreReqBean) {

        if (getArticleInfoByArticleBrandForHotScoreReqBean == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getArticleInfoByArticleBrandForHotScoreReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByArticleBrandForHotScoreReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Integer> userBrandIds = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(userSubBrandInfoList)) {

            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });

        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandAList = Lists.newArrayList();

        List<ArticleListShowInfo> articleInfoByArticleBrandBList = Lists.newArrayList();

        long brandArticleListShowInfoRecordCount = 0;

        long typeArticleListShowInfoRecordCount = 0;

        int brandArticlePages = 0;

        int typeArticlePages = 0;

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(6);
        long total = 0;
        if (userBrandIds != null && userBrandIds.size() > 0) {

            int userBrandIdsSize = userBrandIds.size();

            //if (userBrandIdsSize == 1) {

            System.out.println("************* getArticleInfoByArticleBrandForHotScore getArticleBrandId :"
                    +getArticleInfoByArticleBrandForHotScoreReqBean.getArticleBrandId());
            if(getArticleInfoByArticleBrandForHotScoreReqBean.getArticleBrandId()!=null) {
                int articleBrandId = getArticleInfoByArticleBrandForHotScoreReqBean.getArticleBrandId();

                //if(pageNum.equals(1)) {
                    //articleInfoService.insertArticleInfoByArticleBrand(articleBrandId);  //暂时屏蔽 20210117
                //}

                PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.getArticleInfoByArticleBrandForHotScore(pageNum, pageSize, articleBrandId, null,springProfilesActive);
                total = articleListShowInfoPageInfo.getTotal();
                brandArticleListShowInfoRecordCount = articleListShowInfoPageInfo.getTotal();

                brandArticlePages = articleListShowInfoPageInfo.getPages();

                articleInfoByArticleBrandBList.addAll(articleListShowInfoPageInfo.getList());
            }
//            } else {
//
//                int articleBrandIdA = userBrandIds.get(0);
//
//                PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.getArticleInfoByArticleBrandForHotScore(pageSize, pageNum, articleBrandIdA, null);
//
//                articleInfoByArticleBrandBList = articleListShowInfoPageInfo.getList();
//            }

            if (!CollectionUtils.isEmpty(articleInfoByArticleBrandAList)) {
                articleInfoByArticleBrandAList.forEach(info -> {
                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

            if (!CollectionUtils.isEmpty(articleInfoByArticleBrandBList)) {
                articleInfoByArticleBrandBList.forEach(info -> {
                    /* ljt 20210130 热度伪造 start*/
                    info.setArticleHotValue(ToolUtil.setArticleHotValue(info.getArticleHotValue()));
                    /* ljt 20210130 热度伪造 end*/

                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

        }

        log.info("[brandArticleListShowInfoRecordCount] = " + brandArticleListShowInfoRecordCount
                + " [typeArticleListShowInfoRecordCount] = " + typeArticleListShowInfoRecordCount);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        // continueQueryFlag 0=已查询完 1=未查询完
        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandBList) && articleInfoByArticleBrandBList.size() > 0) {

            boolean conditionOne = (brandArticleListShowInfoRecordCount <= pageSize.intValue()) && (typeArticleListShowInfoRecordCount <= pageSize.intValue());
            boolean conditionTwo = articleInfoByArticleBrandBList.size() < pageSize.intValue();
            boolean conditionThree = (brandArticlePages <= pageNum && typeArticlePages <= pageNum);

            if (conditionOne || conditionTwo || conditionThree) {

                resultMap.put("continueQueryFlag", 0);

            } else {

                resultMap.put("continueQueryFlag", 1);

            }

        } else {

            resultMap.put("continueQueryFlag", 0);

        }

        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandAList)) {

            //多关注多个品牌时，最少要大于最低值，才能继续分页
            if (articleInfoByArticleBrandAList.size() >= pageSize.intValue() / 5) {
                resultMap.put("continueQueryFlag", 1);
            } else {
                resultMap.put("continueQueryFlag", 0);
            }

        }

        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandAList) && CollectionUtils.isNotEmpty(articleInfoByArticleBrandBList)) {

            resultMap.put("continueQueryFlag", 0);

        }
        if(total <= 15 && resultMap.get("continueQueryFlag").equals(0)){
            List<ArticleListShowInfo> info =  articleInfoService.getLinkArticle(getArticleInfoByArticleBrandForHotScoreReqBean.getArticleBrandId());
            if(info != null && info.size()>0){
                articleInfoByArticleBrandBList.addAll(info);
            }
        }
        //long count = articleInfoByArticleBrandPageInfo.getTotal();
        resultMap.put("count", 100000);
        resultMap.put("total", total);
        resultMap.put("items", articleInfoByArticleBrandBList);

        if (CollectionUtils.isEmpty(articleInfoByArticleBrandBList) || articleInfoByArticleBrandBList.size() == 0) {

            resultMap.put("items", articleInfoByArticleBrandAList);

            respData.setData(resultMap);
            respData.setMsg("暂无更多");
            return respData;

        }

        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    //之前的版本 20200119
    @PostMapping(value = "/getArticleInfoByArticleBrandForHotScore_old", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByArticleBrandForHotScore_old(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive, @RequestBody GetArticleInfoByArticleBrandForHotScoreReqBean getArticleInfoByArticleBrandForHotScoreReqBean) {

        if (getArticleInfoByArticleBrandForHotScoreReqBean == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getArticleInfoByArticleBrandForHotScoreReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByArticleBrandForHotScoreReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));

        List<Integer> userBrandIds = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(userSubBrandInfoList)) {

            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });

        }

        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandAList = Lists.newArrayList();

        List<ArticleListShowInfo> articleInfoByArticleBrandBList = Lists.newArrayList();

        long brandArticleListShowInfoRecordCount = 0;

        long typeArticleListShowInfoRecordCount = 0;

        int brandArticlePages = 0;

        int typeArticlePages = 0;

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(6);

        if (userBrandIds != null && userBrandIds.size() > 0) {

            int userBrandIdsSize = userBrandIds.size();

            if (userBrandIdsSize == 1) {

                int articleBrandId = userBrandIds.get(0);

                PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.getArticleInfoByArticleBrandForHotScore(pageNum, pageSize, articleBrandId, null,springProfilesActive);

                brandArticleListShowInfoRecordCount = articleListShowInfoPageInfo.getTotal();

                brandArticlePages = articleListShowInfoPageInfo.getPages();

                articleInfoByArticleBrandBList.addAll(articleListShowInfoPageInfo.getList());

                //查询品牌的“内部分类”，把内部分类的文章也加载出来，暂时屏蔽
                List<BrandSupplyInfo> brandSupplyInfoList = brandSupplyInfoService.getBrandSupplyInfo(articleBrandId);
                if (CollectionUtils.isNotEmpty(brandSupplyInfoList) && brandSupplyInfoList.size() > 0) {

                    Integer articleTypeId = brandSupplyInfoList.get(0).getArticleTypeId();
                    PageInfo<ArticleListShowInfo> articleListShowInfoOfTypePageInfo = articleInfoService.getArticleInfoByArticleTypeForHotScore(pageNum, pageSize, articleTypeId, null,springProfilesActive);

                    List<ArticleListShowInfo> articleListShowInfos =  articleListShowInfoOfTypePageInfo.getList();
                    if (!CollectionUtils.isEmpty(articleListShowInfos)) {
                        articleListShowInfos.forEach(info -> {

                            if (info != null) {
                                info.setArticleBrandId(articleBrandId);
                            }

                        });
                    }

                    typeArticleListShowInfoRecordCount = articleListShowInfoOfTypePageInfo.getTotal();

                    typeArticlePages = articleListShowInfoOfTypePageInfo.getPages();

                    articleInfoByArticleBrandBList.addAll(articleListShowInfos);

                }

            } else if (userBrandIdsSize == 2) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), pageSize / 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), pageSize / 2);

                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_two);

            } else if (userBrandIdsSize == 3) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 4);

                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_three);

            } else if (userBrandIdsSize == 4) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 3);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 2);

                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_four);

            } else if (userBrandIdsSize == 5) {

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_one = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(0), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_two = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(1), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_three = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(2), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_four = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(3), 2);

                List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList_five = articleInfoService.getArticleInfoByBrandForRand(userBrandIds.get(4), 2);

                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_one);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_two);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_three);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_four);
                articleInfoByArticleBrandAList.addAll(articleInfoByArticleBrandList_five);

            } else {

                int articleBrandIdA = userBrandIds.get(0);

                PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.getArticleInfoByArticleBrandForHotScore(pageSize, pageNum, articleBrandIdA, null,springProfilesActive);

                articleInfoByArticleBrandBList = articleListShowInfoPageInfo.getList();
            }

            if (!CollectionUtils.isEmpty(articleInfoByArticleBrandAList)) {
                articleInfoByArticleBrandAList.forEach(info -> {
                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

            if (!CollectionUtils.isEmpty(articleInfoByArticleBrandBList)) {
                articleInfoByArticleBrandBList.forEach(info -> {
                    Integer articleBrandId = info.getArticleBrandId();
                    if (articleBrandId != null) {
                        String articleBrandName = brandInfoService.getBrandInfoByBrandId(articleBrandId);
                        info.setArticleBrandName(articleBrandName);
                    }
                });
            }

        }

        log.info("[brandArticleListShowInfoRecordCount] = " + brandArticleListShowInfoRecordCount
                + " [typeArticleListShowInfoRecordCount] = " + typeArticleListShowInfoRecordCount);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandBList) && articleInfoByArticleBrandBList.size() > 0) {

            boolean conditionOne = (brandArticleListShowInfoRecordCount <= pageSize.intValue()) && (typeArticleListShowInfoRecordCount <= pageSize.intValue());
            boolean conditionTwo = articleInfoByArticleBrandBList.size() < pageSize.intValue();
            boolean conditionThree = (brandArticlePages <= pageNum && typeArticlePages <= pageNum);

            if (conditionOne || conditionTwo || conditionThree) {

                resultMap.put("continueQueryFlag", 0);

            } else {

                resultMap.put("continueQueryFlag", 1);

            }

        } else {

            resultMap.put("continueQueryFlag", 0);

        }

        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandAList)) {

            //多关注多个品牌时，最少要大于最低值，才能继续分页
            if (articleInfoByArticleBrandAList.size() >= pageSize.intValue() / 5) {
                resultMap.put("continueQueryFlag", 1);
            } else {
                resultMap.put("continueQueryFlag", 0);
            }

        }

        if (CollectionUtils.isNotEmpty(articleInfoByArticleBrandAList) && CollectionUtils.isNotEmpty(articleInfoByArticleBrandBList)) {

            resultMap.put("continueQueryFlag", 0);

        }

        //long count = articleInfoByArticleBrandPageInfo.getTotal();
        resultMap.put("count", 100000);
        resultMap.put("items", articleInfoByArticleBrandBList);

        if (CollectionUtils.isEmpty(articleInfoByArticleBrandBList) || articleInfoByArticleBrandBList.size() == 0) {

            resultMap.put("items", articleInfoByArticleBrandAList);

        }

        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }



    @PostMapping(value = "/getArticleInfoByKeyWordsForHotScore", produces = "application/json;charset=UTF-8")
    public RespData getArticleInfoByKeyWordsForHotScore(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByKeyWordsForHotScoreReqBean getArticleInfoByKeyWordsForHotScoreReqBean) {

        if (getArticleInfoByKeyWordsForHotScoreReqBean == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getArticleInfoByKeyWordsForHotScoreReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByKeyWordsForHotScoreReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        //获取用户关注的品牌
//        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
//
//        List<Integer> userBrandIds = Lists.newArrayList();
//        if (CollectionUtils.isNotEmpty(userSubBrandInfoList)) {
//
//            userSubBrandInfoList.stream().forEach(info -> {
//                userBrandIds.add(info.getBrandId());
//            });
//
//        }

        List<ArticleListShowInfo> articleInfoByArticleBrandBList = Lists.newArrayList();

        //if (userBrandIds != null && userBrandIds.size() > 0) {

            if(getArticleInfoByKeyWordsForHotScoreReqBean.getKeywords()!=null) {
                String keywords = getArticleInfoByKeyWordsForHotScoreReqBean.getKeywords();

                PageInfo<ArticleListShowInfo> articleListShowInfoPageInfo = articleInfoService.queryArticleInfoByKeyWorksForHotScore(pageNum, pageSize, getArticleInfoByKeyWordsForHotScoreReqBean.getKeywords());


                articleInfoByArticleBrandBList.addAll(articleListShowInfoPageInfo.getList());
            }

        //}

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        resultMap.put("count", 100000);
        resultMap.put("items", articleInfoByArticleBrandBList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }


    @PostMapping(value = "/getUserMicroStationArticleInfo", produces = "application/json;charset=UTF-8")
    public RespData getUserMicroStationArticleInfo(@RequestHeader("userId") String userId, @RequestBody GetUserMicroStationArticleInfoReqBean getUserMicroStationArticleInfoReqBean) {

        if (getUserMicroStationArticleInfoReqBean == null || getUserMicroStationArticleInfoReqBean.getOtherId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer pageNum = getUserMicroStationArticleInfoReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getUserMicroStationArticleInfoReqBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        Integer otherId = getUserMicroStationArticleInfoReqBean.getOtherId();
        PageInfo<CombinedUserOwnArticleInfo> userOwnArticleInfoPageInfo = articleInfoService.getUserOwnArticleInfo(pageNum, pageSize, otherId);

        List<CombinedUserOwnArticleInfo> userOwnArticleInfoList = userOwnArticleInfoPageInfo.getList();

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        long count = userOwnArticleInfoPageInfo.getTotal();
        resultMap.put("count", count);
        resultMap.put("items", userOwnArticleInfoList);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @PostMapping(value = "/scanTextContent", produces = "application/json;charset=UTF-8")
    public RespData scanTextContent(@RequestHeader("userId") String userId, @RequestBody ScanTextContentReqBean scanTextContentReqBean) throws Exception {

        if (scanTextContentReqBean == null || StringUtils.isBlank(scanTextContentReqBean.getTextContent())) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        String scanResult = AliyunGreenClientUtil.textScan(scanTextContentReqBean.getTextContent());

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        //scanStatus 0-文本违规 1-文本正常
        resultMap.put("scanStatus", 0);

        if ("politics".equalsIgnoreCase(scanResult)) {

            resultMap.put("scanMsg", "可能包含 政治敏感 内容，请修改，如有问题 请联系官方客服。");

        } else if ("porn".equalsIgnoreCase(scanResult)) {

            resultMap.put("scanMsg", "可能包含 色情违规 内容，请修改， 如有问题 请联系官方客服。");

        } else {
            resultMap.put("scanStatus", 1);
            resultMap.put("scanMsg", "正常");
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/getNotFoundPageRelationInfo", produces = "application/json;charset=UTF-8")
    public RespData getNotFoundPageRelationInfo(@RequestHeader("userId") String userId) {

        List<ArticleListShowInfo> articleListShowInfos_one = articleInfoService.getArticleInfoByArticleTypeForHotScoreBySpecialSize(1, null, 1);

        List<ArticleListShowInfo> articleListShowInfos_two = articleInfoService.getArticleInfoByArticleTypeForHotScoreBySpecialSize(5, null, 1);

        articleListShowInfos_one.addAll(articleListShowInfos_two);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);

        resultMap.put("articleInfo", articleListShowInfos_one);

        Map<String, Object> userInfoMap = Maps.newHashMapWithExpectedSize(7);
        UserInfo userInfo = userInfoService.getUserMainInfo(Integer.parseInt(userId));
        //文章所有者的用户信息
        userInfoMap.put("userId", String.valueOf(userInfo.getUserId()));
        userInfoMap.put("nickName", userInfo.getNickName());
        userInfoMap.put("avatarUrl", userInfo.getAvatarUrl());
        userInfoMap.put("qrcodeUrl", userInfo.getQrcodeUrl());
        userInfoMap.put("telNum", userInfo.getTelNum());

        //获取用户选中的品牌信息(有效微站)
        BrandInfo selectBrandInfo = userBrandInfoService.getUserSelectBrandInfo(Integer.parseInt(userId));
        String userBrandName = "";
        if (selectBrandInfo != null) {
            userBrandName = selectBrandInfo.getBrandName();
        }
        userInfoMap.put("userBrandName", userBrandName);

        resultMap.put("userInfo", userInfoMap);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    /**
     * 封面图上传
     * 20200430 yl
     * @param userId
     * @param uploadArticleThumbnail
     * @return
     * @throws IOException
     */
    @RequestMapping(value="/uploadArticleThumbnail", method = RequestMethod.POST)
    public RespData uploadArticleThumbnail(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive,  @RequestBody UploadWxUserQrCodeImgReqBean uploadArticleThumbnail){

        if (uploadArticleThumbnail  == null || StringUtils.isBlank(uploadArticleThumbnail.getMediaId())) {

            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;

        }

        String articleThumbnailUrl = null;

        String mediaId = uploadArticleThumbnail.getMediaId();

        log.info("[articleThumbnailMediaId] = " +mediaId);

        Map<String, String> resultMap = Maps.newHashMap();

        try {

//            WeixinServiceDL weixinService= objectFactory.getObject();
//            weixinService.reSetConfigStorage(springProfilesActive);
            //PlatformSysInfo platformSysInfo=sysGzhService.getPlatformSysInfo(springProfilesActive);
            //WxMpServiceImpl weixinService = WeixinServiceNew.getWeixinService(platformSysInfo.getSysGzh());

            springProfilesActive=WeixinServiceMap.getReplaceGzh(springProfilesActive);//找替换的 公众号code 20210816

            WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(springProfilesActive);

            File articleThumbnailFile = weixinService.getMaterialService().mediaDownload(mediaId);

            String fileName = articleThumbnailFile.getName();

            log.info("[articleThumbnailFileName] = " + fileName);

            String formatDate = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
            String dirName = SysConstant.USER_QRCODE_IMG_OSS_DIR + userId + "/" + formatDate + "/";

            AliyunOssClientUtil.uploadFileByLocalFile(articleThumbnailFile, dirName + fileName);

            articleThumbnailUrl = SysConstant.USER_QRCODE_OSS_ACCESS_PREFIX + dirName + fileName;

            resultMap.put("articleThumbnailUrl", articleThumbnailUrl);

        } catch (WxErrorException e) {
            e.printStackTrace();
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 分页查询视频
     * @param userId
     * @param getArticleInfoByArticleBrandForHotScoreReqBean
     * @return
     */
    @PostMapping(value = "/selectArticleByVideo", produces = "application/json;charset=UTF-8")
    public RespData selectArticleByVideo(@RequestHeader("userId") String userId , @RequestHeader("identifying") String identifying, @RequestBody GetArticleInfoByArticleBrandForHotScoreReqBean getArticleInfoByArticleBrandForHotScoreReqBean) {
        Integer pageNum = getArticleInfoByArticleBrandForHotScoreReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getArticleInfoByArticleBrandForHotScoreReqBean.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 3;
        }
        //获取用户关注的品牌
        List<UserBrandCombinedInfo> userSubBrandInfoList = userBrandInfoService.getUserBrandInfo(Integer.parseInt(userId));
        // 关注的品牌id集合
        List<Integer> userBrandIds = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(userSubBrandInfoList)) {
            userSubBrandInfoList.stream().forEach(info -> {
                userBrandIds.add(info.getBrandId());
            });
        }
        // 关注的类型id集合
        List<Integer> userConcernArticleTypeIds = this.connectionInfoService.getUserAttentionArticleTypeInfo(Integer.valueOf(userId));

        if (CollectionUtils.isEmpty(userConcernArticleTypeIds)) {
            userConcernArticleTypeIds = userArticleTypeInfoService.getUserConcernArticleTypeInfo(Integer.parseInt(userId));
            if (userConcernArticleTypeIds == null) {
                userConcernArticleTypeIds = Lists.newArrayList();

            }

            userConcernArticleTypeIds.add(1);

        }
        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(identifying);
        //String[] realmArr = {platformSysInfo.getShareDomainUrl(),platformSysInfo.getFrontDomain(),platformSysInfo.getSysGzh().getRealmResource()};
        String[] realmArr = {platformSysInfo.getShareDomainUrl()};
        int index = (int) (Math.random() * realmArr.length);
        String mainlink=realmArr[index];

        List<ArticleInfo> articles = articleInfoService.selectArticleByVideo(userConcernArticleTypeIds, userBrandIds,pageNum,pageSize);
        RespData respData = new RespData();
        if(CollectionUtils.isNotEmpty(articles)){
            List<VidoeListDto> collect = articles.stream().map(articleInfo -> {
                VidoeListDto video = new VidoeListDto();
                video.setId(articleInfo.getId());
                video.setUrl(articleInfo.getVideoUrl());//视频url
                video.setCover(articleInfo.getArticleImgUrl());//视频摘要图片
                video.setDes(articleInfo.getArticleContent());
                video.setTitle(articleInfo.getArticleTitle());//标题
                video.setShareDes(articleInfo.getArticleDesc());//分享配文
                video.setVideoHeight(articleInfo.getVideoHeight());// 视频高度
                UserInfo userInfo = userInfoService.getUserMainInfo(articleInfo.getUserId());
                if (null == userInfo){
                    userInfo = userInfoService.getUserMainInfo(Integer.valueOf(userId));
                }
                video.setAuthor_id(userInfo.getUserId());
                video.setAuthor(userInfo.getNickName());
                video.setTag_image(userInfo.getAvatarUrl());//用户头像
                video.setQrcode_url(userInfo.getQrcodeUrl());//微信二维码
                video.setTelNum(userInfo.getTelNum());//电话
                video.setFabulous(false);
                video.setTagFollow(false);
                video.setMainLink(mainlink);
                return video;
            }).collect(Collectors.toList());
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setData(collect);
            respData.setMsg("成功");
            return respData;
        }
        respData.setCode(ReturnCode.SERVER_ERROR);
        respData.setMsg("服务器异常");
        return respData;
    }

    /**
     * 新版分页查询素材
     * 类型：3
     * yl 20200626
     * @param userId
     * @param articleInfoByArticleReqBean
     * @return
     */
    @PostMapping(value = "/selectArticleByMaterial", produces = "application/json;charset=UTF-8")
    public RespData selectArticleByMaterial(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByArticleReqBean articleInfoByArticleReqBean) {
        Integer pageNum = articleInfoByArticleReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = articleInfoByArticleReqBean.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 5;
        }
        RespData respData = new RespData();
        List<ArticleRespEntity> articleRespEntities = this.articleInfoService.selectArticleByMaterial(pageNum,pageSize,articleInfoByArticleReqBean,Integer.valueOf(userId));
        if (CollectionUtils.isEmpty(articleRespEntities)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("items", articleRespEntities);

        List<ArticleRespEntity> articleRespEntitiesAddOne = this.articleInfoService.selectArticleByMaterial(pageNum+1,pageSize,articleInfoByArticleReqBean,Integer.valueOf(userId));
        if (CollectionUtils.isEmpty(articleRespEntitiesAddOne)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setData(resultMap);
            respData.setMsg("下页无数据");
            return respData;
        }

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 通过素材id查询素材图片
     * @param userId
     * @param materialImgInfo
     * @return
     */
    @PostMapping(value = "/selectMaterialImgByArticleId", produces = "application/json;charset=UTF-8")
    public RespData selectMaterialImgByArticleId(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying, @RequestBody MaterialImgInfo materialImgInfo) {
        RespData respData = new RespData();
        if (null == materialImgInfo){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("传参错误");
            return respData;
        }

        ArticleLookDetailLog articleLookDetailLog=new ArticleLookDetailLog();
        articleLookDetailLog.setArticleId(materialImgInfo.getArticleId());
        articleLookDetailLog.setUserId(Integer.valueOf(userId));
        articleLookDetailLog.setGzhCode(identifying);
        articleLookDetailLog.setLookTime(new Date());
        articleLookDetailLog.setResourceType(3);
        addLookLog(articleLookDetailLog);

        List<String> imgUrls = this.articleInfoService.selectMaterialImgByArticleId(materialImgInfo.getArticleId());
        if (CollectionUtils.isNotEmpty(imgUrls)){
            Map<String,Object> map = Maps.newHashMapWithExpectedSize(2);
            map.put("imgUrls",imgUrls);
            // 查询该用户是否可以保存本地
            //log.error("****[userId] :" + userId+"____materialImgInfo.getArticleId():"+materialImgInfo.getArticleId()+"____springProfilesActive:"+identifying);
            boolean isSaveLocally = this.articleInfoService.isSaveLocally(Integer.valueOf(userId),materialImgInfo.getArticleId(),identifying);
            map.put("isSaveLocally",isSaveLocally);
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setData(map);
            respData.setMsg("成功");
            return respData;
        }
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("暂无数据");
        return respData;
    }

    /**
     * 新版点赞以及取消赞
     * yl 20200627
     * @param userId
     * @param articleLikeReqBean
     * @return 点赞状态值(-1:参数异常, 0-取消点赞 1-已点赞)
     */
    @PostMapping(value = "/giveLikeByArticleId", produces = "application/json;charset=UTF-8")
    public RespData giveLikeByArticleId(@RequestHeader("userId") String userId, @RequestBody ArticleLikeReqBean articleLikeReqBean) {
        if (articleLikeReqBean == null || articleLikeReqBean.getArticleId() == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        int articleLikeStatus = this.articleInfoService.giveLikeByArticleId(Integer.valueOf(userId), articleLikeReqBean.getArticleId());

        HashMap<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        // 点赞数
//        resultMap.put("articleLikeCount", articleInfoService.getArticleLikeCount(articleLikeReqBean.getArticleId()));// 真实值 2022-03-28 配合接口(/getArticleDetailInfo) 的返回值 articleLikeCount
        int articleLikeCount = Optional.ofNullable(articleLikeReqBean.getArticleLikeCount()).orElse(0);// 虚拟值 2022-03-28
        if (articleLikeStatus == 1) {
            articleLikeCount++;
        } else if (articleLikeStatus == 0) {
            articleLikeCount--;
        }

        resultMap.put("articleLikeCount", articleLikeCount);
        resultMap.put("articleLikeStatus", articleLikeStatus);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }

    /**
     * 新版分页查询文章
     * yl 20200627
     * 类型：1
     * @param userId
     * @param articleInfoByArticleReqBean
     * @return
     */
    @PostMapping(value = "/getArticle", produces = "application/json;charset=UTF-8")
    public RespData getArticle(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByArticleReqBean articleInfoByArticleReqBean) {
        Integer pageNum = articleInfoByArticleReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = articleInfoByArticleReqBean.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 5;
        }
        RespData respData = new RespData();
        List<ArticleRespEntity> articleRespEntities = this.articleInfoService.getArticle(pageNum,pageSize,articleInfoByArticleReqBean,Integer.valueOf(userId));
        if (CollectionUtils.isEmpty(articleRespEntities)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(articleRespEntities);
        respData.setMsg("成功");
        return respData;
    }


    /**
     * 新版分页查询视频
     * yl 20200627
     * 类型：2
     * @param userId
     * @param articleInfoByArticleReqBean
     * @return
     */
    @PostMapping(value = "/getArticleByVideo", produces = "application/json;charset=UTF-8")
    public RespData getArticleByVideo(@RequestHeader("userId") String userId, @RequestBody GetArticleInfoByArticleReqBean articleInfoByArticleReqBean) {
        Integer pageNum = articleInfoByArticleReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = articleInfoByArticleReqBean.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 5;
        }
        RespData respData = new RespData();
        List<ArticleInfo> articleRespEntities = this.articleInfoService.getArticleByVideo(pageNum,pageSize,articleInfoByArticleReqBean,Integer.valueOf(userId));
        if (CollectionUtils.isEmpty(articleRespEntities)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(articleRespEntities);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * yl 20200708
     * 用户上传素材
     * @param userId
     * @param articleRespEntity
     * @return
     */
    @PostMapping(value = "/userAddMaterial", produces = "application/json;charset=UTF-8")
    public RespData userAddMaterial(@RequestHeader("userId") String userId, @RequestBody ArticleRespEntity articleRespEntity) {
        RespData respData = new RespData();
        if (null == articleRespEntity){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("请填写素材内容");
            return respData;
        }
        if (null == articleRespEntity.getArticleDesc()){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("请填写素材内容!");
            return respData;
        }
        if ((null == articleRespEntity.getArticleBrandId()) && (null == articleRespEntity.getArticleTypeId())){
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("你好，请选择素材品牌或素材分类！");
            return respData;
        }
        articleRespEntity.setUserId(Integer.valueOf(userId));
        articleRespEntity.setArticleSource(2); // 用户添加
        articleRespEntity.setResourceType(3);// 素材
        articleRespEntity.setArticleStatus(0);// 用户上传的素材需要审核
        articleRespEntity.setCreateTime(new Date());
        articleRespEntity.setArticleHotScore(new Random().nextInt(100) + 1);
        this.articleInfoService.addUserAttentionMaterial(articleRespEntity);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    /**
     * 多张素材图上传
     * 20200708 yl
     * @param userId
     * @param uploadArticleThumbnail
     * @return
     * @throws IOException
     */
    @RequestMapping(value="/uploadMaterialImg", method = RequestMethod.POST)
    public RespData uploadMaterialImg(@RequestHeader("userId") String userId,@RequestHeader("identifying") String springProfilesActive,  @RequestBody UploadWxUserQrCodeImgReqBean uploadArticleThumbnail) {
        System.out.println("请求参数" + uploadArticleThumbnail.getMediaIds().toString());
        RespData respData = new RespData();
        /*if (uploadArticleThumbnail  == null || StringUtils.isBlank(uploadArticleThumbnail.getMediaIds())) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("参数异常");
            return respData;

        }

        List<String> mediaIds = Arrays.asList(uploadArticleThumbnail.getMediaIds().split(","));*/
        if (CollectionUtils.isEmpty(uploadArticleThumbnail.getMediaIds()) || uploadArticleThumbnail.getMediaIds().size() > 9) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("最多只能上传九张图片哦");
            return respData;
        }
        Map<String, List<String>> resultMap = Maps.newHashMap();
        List<String> urlList = Lists.newArrayList();

        uploadArticleThumbnail.getMediaIds().forEach(mediaId -> {
            try {

//                WeixinServiceDL weixinService = objectFactory.getObject();
//                weixinService.reSetConfigStorage(springProfilesActive);
                //PlatformSysInfo platformSysInfo=sysGzhService.getPlatformSysInfo(springProfilesActive);
                //WxMpServiceImpl weixinService = WeixinServiceNew.getWeixinService(platformSysInfo.getSysGzh());

                String spa= WeixinServiceMap.getReplaceGzh(springProfilesActive);//找替换的 公众号code 20210816

                WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(spa);

                String articleThumbnailUrl = null;
                File articleThumbnailFile = weixinService.getMaterialService().mediaDownload(mediaId);

                String fileName = articleThumbnailFile.getName();

                log.info("[articleThumbnailFileName] = " + fileName);

                String formatDate = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
                String dirName = SysConstant.USER_QRCODE_IMG_OSS_DIR + userId + "/" + formatDate + "/";

                AliyunOssClientUtil.uploadFileByLocalFile(articleThumbnailFile, dirName + fileName);

                articleThumbnailUrl = SysConstant.USER_QRCODE_OSS_ACCESS_PREFIX + dirName + fileName;

                urlList.add(articleThumbnailUrl);
            } catch (WxErrorException e) {
                e.printStackTrace();
            }
        });
        resultMap.put("articleThumbnailUrl", urlList);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }


    /**
     * yl 20200709
     * 查询用户自己上传的素材
     * @param userId
     * @param articleInfoByArticleReqBean
     * @return
     */
    @PostMapping(value = "/selectMaterialByUserId", produces = "application/json;charset=UTF-8")
    public RespData selectMaterialByUserId(@RequestHeader("userId") String userId,@RequestBody GetArticleInfoByArticleReqBean articleInfoByArticleReqBean) {
        Integer pageNum = articleInfoByArticleReqBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = articleInfoByArticleReqBean.getPageSize();
        if (pageSize == null || pageSize.intValue() <= 0) {
            pageSize = 5;
        }
        RespData respData = new RespData();
        List<ArticleRespEntity> articleRespEntities = this.articleInfoService.selectMaterialByUserId(pageNum,pageSize,Integer.valueOf(userId));
        if (CollectionUtils.isEmpty(articleRespEntities)){
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("暂无数据");
            return respData;
        }
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(articleRespEntities);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * yl 20200709
     * 用户删除自己上传的素材
     * @param userId
     * @param articleInfo
     * @return
     */
    @PostMapping(value = "/delMaterialById", produces = "application/json;charset=UTF-8")
    public RespData delMaterialById(@RequestHeader("userId") String userId,@RequestBody ArticleInfo articleInfo) {
        articleInfo.setUserId(Integer.valueOf(userId));
        this.articleInfoService.delMaterialById(articleInfo);
        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     *
     * @param userId
     * @param articleInfo
     * @return
     */
    @PostMapping(value = "/addMaterialVideoByInfo", produces = "application/json;charset=UTF-8")
    public RespData addMaterialVideoByInfo(@RequestHeader("userId") String userId,@RequestBody ArticleInfo articleInfo, HttpServletRequest request) throws IOException {
        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(4);

        // 查询会员状态
        Integer vipStatus = userInfoService.getUserVipStatus(Integer.valueOf(userId));

        Integer NotVipVideoCount = 0;

        // 如果不是会员
        if(vipStatus == null || vipStatus == 0){

            vipStatus = 0;
            NotVipVideoCount = (Integer) Optional.ofNullable(redisCacheUtil.getCacheObject(TRICKORTREAT + userId)).orElse(0);

            if(NotVipVideoCount >= 3){

                resultMap.put("vipStatus", vipStatus);
                resultMap.put("notVipVideoCount", NotVipVideoCount);
                respData.setData(resultMap);
                respData.setCode(ReturnCode.NORMAL_SUCC);
                respData.setMsg("您不是会员，上传视频达到三次！");
                return respData;
            }
        }

        String strViedo = articleInfo.getVideoUrl();

        MultipartFile file= Base64DecodeMultipartFile.base64Convert(strViedo);

        if (file.getSize() == 0) {
            resultMap.put("webShowPath", "0");
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setData(resultMap);
            respData.setMsg("请选择文件！");
            return respData;
        }

        // 文件不大于10M
//        boolean fileSize = ToolUtil.checkFileSize( file.getSize(),10,"M");
//        if (!fileSize) {
//            resultMap.put("webShowPath", "0");
//            respData.setCode(ReturnCode.NORMAL_SUCC);
//            rFespData.setData(resultMap);
//            respData.setMsg("文件不能大于10MB！");
//            return respData;
//        }

        //获取文件后缀
        String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1)
                .toLowerCase();

        // 修改IOS文件后缀
        if("quicktime".equals(fileExt)){
            fileExt = "mp4";
        }

        // 重构文件名称
        String pikId = UUID.randomUUID().toString().replaceAll("-", "");
        String fileName = pikId + "." + fileExt;

        //保存视频
        String formatDate = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
        String dirName = SysConstant.USER_VIDEO_OSS_DIR + userId + "/" + formatDate + "/";

        //在默认临时文件目录中创建一个空文件，使用给定前缀和后缀生成其名称。
        File tempFile = File.createTempFile(UUID.randomUUID().toString(), "tmp");
        File targetFile = File.createTempFile(UUID.randomUUID().toString(), ".mp4");

        //把file（MultipartFile）写道file2(File)。
        file.transferTo(tempFile);
        File compressionFile = MultimediaCompressionUtil.compressionVideo(tempFile, targetFile);

        //在JVM退出时删除文件。也可以调用file.delete();立即删除文件。
        tempFile.deleteOnExit();
        targetFile.deleteOnExit();

        asyncUploadViedo(compressionFile, dirName + fileName);

        Integer userIdInt = Integer.valueOf(userId);
        setVipStatusVideoTime(userIdInt);

        // 视频
        String webShowPath = SysConstant.USER_VIDEO_OSS_ACCESS_PREFIX + dirName + fileName;

        // 封面截图
//        if(articleInfo.getArticleImgUrl() == null || "".equals(articleInfo.getArticleImgUrl())) {
//            String screenshot = webShowPath + "?x-oss-process=video/snapshot,t_1000,f_jpg,w_600,h_800,m_fast";
//            articleInfo.setArticleImgUrl(screenshot);
//        }

        articleInfo.setVideoUrl(webShowPath);
        articleInfo.setUserId(Integer.valueOf(userId));

        int id = this.articleInfoService.addMaterialVideoByInfo(articleInfo);

        NotVipVideoCount = (Integer) redisCacheUtil.getCacheObject(TRICKORTREAT + userId);

        resultMap.put("id", id);
        resultMap.put("vipStatus", vipStatus);
        resultMap.put("notVipVideoCount", NotVipVideoCount);
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    @Async
    public void asyncUploadViedo(File tempFile, String dirFileName){
        try {
            AliyunOssClientUtil.uploadFileByLocalFile(tempFile, dirFileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Async
    public void setVipStatusVideoTime(Integer userIdInt){
        try {
            Integer vipStatus = userInfoService.getUserVipStatus(userIdInt);

            // 如果不是会员，计数器加1
            if(vipStatus == null || vipStatus == 0){
                redisTemplate.opsForValue().increment(TRICKORTREAT + userIdInt,1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param userId
     * @param articleInfo
     * @return
     */
    @PostMapping(value = "/updateMaterialVideoByInfo", produces = "application/json;charset=UTF-8")
    public RespData updateMaterialVideoByInfo(@RequestHeader("userId") String userId,@RequestBody ArticleInfo articleInfo) {
        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(4);

        if(articleInfo == null || articleInfo.getId() == null|| articleInfo.getArticleTitle() == null){
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        articleInfo.setUserId(Integer.valueOf(userId));
        int id = this.articleInfoService.updateMaterialVideoByInfo(articleInfo);

        resultMap.put("id", id);
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 查询非会员计数
     * @param userId
     * @return
     */
    @GetMapping(value = "/getVipStatusVideoTime", produces = "application/json;charset=UTF-8")
    public RespData getVipStatusVideoTime(@RequestHeader("userId") String userId) {
        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        // 查询会员状态
        Integer vipStatus = userInfoService.getUserVipStatus(Integer.valueOf(userId));

        Integer NotVipVideoCount = 0;

        // 如果不是会员
        if(vipStatus == null || vipStatus == 0){
            vipStatus = 0;

            Integer count = (Integer) Optional.ofNullable(redisCacheUtil.getCacheObject(TRICKORTREAT + userId)).orElse(0);

            if(count != null){
                NotVipVideoCount = count;
            }
        }

        resultMap.put("vipStatus", vipStatus);
        resultMap.put("notVipVideoCount", NotVipVideoCount);
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 获取用户品牌海报信息
     * @param userId
     * @return
     */
    @PostMapping(value = "/getUserBandPosterImgInfoList", produces = "application/json;charset=UTF-8")
    public RespData getUserBandPosterImgInfoList(@RequestHeader("userId") String userId) {
        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        List<UserBrandInfo> userBandPosterImgInfoList = userBrandInfoService.queryUserBandPosterImgInfoList(Integer.parseInt(userId));

        if(CollectionUtils.isNotEmpty(userBandPosterImgInfoList)){
            resultMap.put("userBandPosterImgInfoList", userBandPosterImgInfoList);
        }

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 获取用户某品牌的海报信息
     * @param userId
     * @param userPosterImgByBrandIdReqBean 品牌信息
     * @return
     */
    @PostMapping(value = "/getUserPosterImgByBrandId", produces = "application/json;charset=UTF-8")
    public RespData getUserPosterImgByBrandId(@RequestHeader("userId") String userId, @RequestBody UserPosterImgByBrandIdReqBean userPosterImgByBrandIdReqBean) {
        RespData respData = new RespData();
        if (userPosterImgByBrandIdReqBean  == null || userPosterImgByBrandIdReqBean.getBrandId() == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        UserBrandInfo userBrandInfoDto = new UserBrandInfo();
        userBrandInfoDto.setUserId(Integer.valueOf(userId));
        userBrandInfoDto.setBrandId(Integer.valueOf(userPosterImgByBrandIdReqBean.getBrandId()));

        UserBrandInfo userBrandInfo = userBrandInfoService.queryUserBandPosterImg(userBrandInfoDto);

        List<String> userBrandPosterImgInfoList = new ArrayList<>();
        if (userBrandInfo != null && StringUtils.isNotBlank(userBrandInfo.getBrandPoster())) {
            String[] brandPosters = userBrandInfo.getBrandPoster().split(",");
            Collections.addAll(userBrandPosterImgInfoList, brandPosters);
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        resultMap.put("userBrandPosterImgInfoList", userBrandPosterImgInfoList);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 删除用户品牌海报信息
     * @param userId
     * @return
     */
    @PostMapping(value = "/delectUserBandPosterImg", produces = "application/json;charset=UTF-8")
    public RespData delectUserBandPosterImg(@RequestHeader("userId") String userId, @RequestBody UploadUserBandPosterImg uploadUserBandPosterImg) {
        RespData respData = new RespData();
        if (uploadUserBandPosterImg  == null || uploadUserBandPosterImg.getBrandId() == null) {

            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
        String brandPoster = uploadUserBandPosterImg.getBrandPoster();

        UserBrandInfo userBrandInfo = new UserBrandInfo();
        userBrandInfo.setUserId(Integer.valueOf(userId));
        userBrandInfo.setBrandId(uploadUserBandPosterImg.getBrandId());
        userBrandInfo.setBrandPoster(brandPoster == null ? "" : brandPoster);

        int updateStatus = userBrandInfoService.uploadUserBandPosterImg(userBrandInfo);

        resultMap.put("updateStatus", updateStatus);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 删除用户品牌海报
     * @param userId 用户ID
     * @param updateUserBandPosterImg 更新信息
     * @return
     */
    /*@PostMapping(value = "/deleteUserBrandPosterImg", produces = "application/json;charset=UTF-8")
    public RespData deleteUserBrandPosterImg(@RequestHeader("userId") String userId, @RequestBody UpdateUserBandPosterImg updateUserBandPosterImg) {
        RespData respData = new RespData();
        if (updateUserBandPosterImg  == null || updateUserBandPosterImg.getBrandId() == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        UserBrandInfo userBrandInfo = new UserBrandInfo();
        userBrandInfo.setUserId(Integer.valueOf(userId));
        userBrandInfo.setBrandId(updateUserBandPosterImg.getBrandId());
        String brandPoster = updateUserBandPosterImg.getBrandPoster();
        userBrandInfo.setBrandPoster(brandPoster == null ? "" : brandPoster);

        int updateStatus = userBrandInfoService.uploadUserBandPosterImg(userBrandInfo);

        resultMap.put("updateStatus", updateStatus);

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }*/

    /**ljt 20201110
     * 根据分类或品牌id查询关注的视频
     * @param userId
     * @param getUserVideoByBrandOrTypeBean
     * @return
     */
    @PostMapping(value = "/getVideosByBrandOrType", produces = "application/json;charset=UTF-8")
    public RespData getVideosByBrandOrType(@RequestHeader("userId") String userId, @RequestBody GetUserVideoByBrandOrTypeBean getUserVideoByBrandOrTypeBean) {

        Integer pageNum = getUserVideoByBrandOrTypeBean.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = getUserVideoByBrandOrTypeBean.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        RespData respData = new RespData();
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        if (io.micrometer.core.instrument.util.StringUtils.isBlank(userId) || getUserVideoByBrandOrTypeBean == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        // 关注的品牌id集合
        List<Integer> userBrandIds = Lists.newArrayList();
        if (getUserVideoByBrandOrTypeBean.getBrandOrTypeItem() == 1 && getUserVideoByBrandOrTypeBean.getBrandOrTypeId() != null) {
            userBrandIds.add(getUserVideoByBrandOrTypeBean.getBrandOrTypeId());
        }

        // 关注的品牌id集合
        List<Integer> userConcernArticleTypeIds = Lists.newArrayList();
        if (getUserVideoByBrandOrTypeBean.getBrandOrTypeItem() == 2 && getUserVideoByBrandOrTypeBean.getBrandOrTypeId() != null) {
            userConcernArticleTypeIds.add(getUserVideoByBrandOrTypeBean.getBrandOrTypeId());
        }

        PageInfo pageInfo = articleInfoService.selectArticleByArticleTypeAndBrandId(userConcernArticleTypeIds, userBrandIds, pageNum, pageSize);
        if (null == pageInfo.getList() || pageInfo.getList().size() <= 0) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂无数据");
            return respData;
        }

        List<ArticleInfo> queryAllByLimitDto = pageInfo.getList();
        if (CollectionUtils.isNotEmpty(queryAllByLimitDto)) {
            List<ArticleInfo> collect = queryAllByLimitDto.stream().map(info -> {

//                ArticleInfo temporary = new ArticleInfo();

                /* ljt 20210130 热度伪造 start*/
                info.setArticleHotValue(ToolUtil.setArticleHotValue(info.getArticleHotValue()));
                /* ljt 20210130 热度伪造 end*/

                info.setArticleId(info.getId());

                return info;
            }).collect(Collectors.toList());

            resultMap.put("msg", pageInfo.isIsLastPage());
            resultMap.put("items", collect);
        }

        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 常见问题 id ，公众号标识，查询 常见问题 多条数据
     * ljt 20201119
     *
     * @param articleTypeIdInfo 实例对象
     * @return 实例对象
     */
    @PostMapping(value = "/selectManualByLimit", produces = "application/json;charset=UTF-8")
    public RespData selectManualByLimit(@RequestHeader("userId") String userId, @RequestHeader("identifying") String identifying, @RequestBody GetArticleInfoByArticleTypeForHotScoreReqBean articleTypeIdInfo) {

        Integer pageNum = articleTypeIdInfo.getPageNum();
        if (pageNum == null || pageNum.intValue() <= 0) {
            pageNum = 1;
        }

        Integer pageSize = articleTypeIdInfo.getPageSize();
        if (pageSize == null || pageNum.intValue() <= 0) {
            pageSize = 10;
        }

        RespData respData = new RespData();

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(identifying) || articleTypeIdInfo == null || articleTypeIdInfo.getArticleTypeId() == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer articleTypeId = articleTypeIdInfo.getArticleTypeId();
        String gzhCode = identifying;

        PageInfo<CombinedArticleInfoByArticleBrand> pageInfo = this.articleInfoService.selectManualByLimit(pageNum, pageSize, articleTypeId, gzhCode);

        if (null == pageInfo || pageInfo.getList().size() <= 0) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("暂无更多");
            return respData;
        }
        List<CombinedArticleInfoByArticleBrand> queryAllByLimitDto = pageInfo.getList();
        if (CollectionUtils.isNotEmpty(queryAllByLimitDto)) {
//            List<ArticleTypeInfo> collect = queryAllByLimitDto.stream().map(info -> {
//
//                ArticleTypeInfo temporary = new ArticleTypeInfo();
//                temporary.setId(info.getArticleId());
////                temporary.setT(info.getId());
//
//                return temporary;
//            }).collect(Collectors.toList());

            Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
            resultMap.put("msg", pageInfo.isIsLastPage());
            resultMap.put("collect", queryAllByLimitDto);

            respData.setData(resultMap);
        }

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("查询成功");
        return respData;
    }

    /**
     * 关注文章策略
     * @param userBrandIds
     * @param userId
     * @return
     */
    public List<CombinedArticleInfoByArticleBrand> getBalaBala(List<Integer> userBrandIds, String userId){
        List<CombinedArticleInfoByArticleBrand> articleInfoByArticleBrandList = Lists.newArrayList();

        // redis key看文章的次
        String verifyKey = SysConstant.LOOK_ARTICLE_TYPE + userId;
        Object verifyValue = Optional.ofNullable(redisCacheUtil.getCacheObject(verifyKey)).orElse("0");
        String compareDate = verifyValue.toString();

        // true-不是今天第一次，false-是今天第一次
        boolean isToday = ToolUtil.getTodayYMD().equals(compareDate);

        /**
         * 1、用户关注一个品牌：
         *
         * 品牌排序：品牌4篇 正能量 健康 销售技巧 +品牌4 正能量 健康 中医养生+···
         *
         * 刷新规则：刚进去都是最新的一批文章，返回就是下一批最新，再返回，第三批最新
         * 文章视频不区分，显示只要是最新的
         */
        if(userBrandIds.size() == 1) {
            if (!isToday) {
                // 4篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 1);
                // 4篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 1);
                // 1篇中医养生(36)
                List<CombinedArticleInfoByArticleBrand> list_seven = articleInfoService.queryArticleInfoOfBrandOrType(1, 12101, 1);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);
                articleInfoByArticleBrandList.addAll(list_seven);

                redisCacheUtil.setCacheObject(verifyKey, ToolUtil.getTodayYMD(), SysConstant.LOOK_ARTICLE_TYPE_EXPIRATION);
            }

            if (isToday) {
                // 4篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 1);
                // 4篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 1);
                // 1篇中医养生(12101)
                List<CombinedArticleInfoByArticleBrand> list_seven = articleInfoService.getArticleInfoByBrandForRandTop50(12101, 1);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);
                articleInfoByArticleBrandList.addAll(list_seven);
            }
        }

        /**
         *
         * 2、用户关注2个品牌：
         *
         * 品牌1 三篇 + 品牌2 两篇 +正能量+健康+循环（ 品牌1 三篇 + 品牌2 两篇 +···
         */
        if(userBrandIds.size() == 2) {
            if (!isToday) {
                // 不够10篇，先获取双倍
                // 3篇关注的品牌1
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 6);
                // 2篇关注的品牌2
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(1), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 2);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 2);

                if(list_one.size() >= 3) {
                    articleInfoByArticleBrandList.add(list_one.get(0));
                    articleInfoByArticleBrandList.add(list_one.get(1));
                    articleInfoByArticleBrandList.add(list_one.get(2));
                }
                if(list_two.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_two.get(0));
                    articleInfoByArticleBrandList.add(list_two.get(1));
                }
                if(list_three.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_three.get(0));
                }
                if(list_four.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_four.get(0));
                }

                if(list_one.size() >= 6) {
                    articleInfoByArticleBrandList.add(list_one.get(3));
                    articleInfoByArticleBrandList.add(list_one.get(4));
                    articleInfoByArticleBrandList.add(list_one.get(5));
                }
                if(list_two.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_two.get(2));
                    articleInfoByArticleBrandList.add(list_two.get(3));
                }
                if(list_three.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_three.get(1));
                }
                if(list_four.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_four.get(1));
                }

                redisCacheUtil.setCacheObject(verifyKey, ToolUtil.getTodayYMD(), SysConstant.LOOK_ARTICLE_TYPE_EXPIRATION);
            }

            if (isToday) {
                // 不够10篇，先获取双倍
                // 3篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 6);
                // 2篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(1), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 2);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 2);

                if(list_one.size() >= 3) {
                    articleInfoByArticleBrandList.add(list_one.get(0));
                    articleInfoByArticleBrandList.add(list_one.get(1));
                    articleInfoByArticleBrandList.add(list_one.get(2));
                }
                if(list_two.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_two.get(0));
                    articleInfoByArticleBrandList.add(list_two.get(1));
                }
                if(list_three.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_three.get(0));
                }
                if(list_four.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_four.get(0));
                }

                if(list_one.size() >= 6) {
                    articleInfoByArticleBrandList.add(list_one.get(3));
                    articleInfoByArticleBrandList.add(list_one.get(4));
                    articleInfoByArticleBrandList.add(list_one.get(5));
                }
                if(list_two.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_two.get(2));
                    articleInfoByArticleBrandList.add(list_two.get(3));
                }
                if(list_three.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_three.get(1));
                }
                if(list_four.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_four.get(1));
                }
            }
        }

        /**
         *
         * 3、用户关注3个品牌：
         *
         * 品牌1 三篇 + 品牌2 两篇 +正能量+健康+ 品牌3两篇 + 循环
         */
        if(userBrandIds.size() == 3) {
            if (!isToday) {
                // 不够10篇，先获取双倍
                // 3篇关注的品牌1
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 6);
                // 2篇关注的品牌2
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(1), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 2);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 2);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(2), 4);

                if(list_one.size() >= 3) {
                    articleInfoByArticleBrandList.add(list_one.get(0));
                    articleInfoByArticleBrandList.add(list_one.get(1));
                    articleInfoByArticleBrandList.add(list_one.get(2));
                }
                if(list_two.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_two.get(0));
                    articleInfoByArticleBrandList.add(list_two.get(1));
                }
                if(list_three.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_three.get(0));
                }
                if(list_four.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_four.get(0));
                }
                if(list_five.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_five.get(0));
                    articleInfoByArticleBrandList.add(list_five.get(1));
                }

                if(list_one.size() >= 6) {
                    articleInfoByArticleBrandList.add(list_one.get(3));
                    articleInfoByArticleBrandList.add(list_one.get(4));
                    articleInfoByArticleBrandList.add(list_one.get(5));
                }
                if(list_two.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_two.get(2));
                    articleInfoByArticleBrandList.add(list_two.get(3));
                }
                if(list_three.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_three.get(1));
                }
                if(list_four.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_four.get(1));
                }
                if(list_five.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_five.get(2));
                    articleInfoByArticleBrandList.add(list_five.get(3));
                }

                redisCacheUtil.setCacheObject(verifyKey, ToolUtil.getTodayYMD(), SysConstant.LOOK_ARTICLE_TYPE_EXPIRATION);
            }

            if (isToday) {
                // 不够10篇，先获取双倍
                // 3篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 6);
                // 2篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(1), 4);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 2);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 2);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(2), 4);

                if(list_one.size() >= 3) {
                    articleInfoByArticleBrandList.add(list_one.get(0));
                    articleInfoByArticleBrandList.add(list_one.get(1));
                    articleInfoByArticleBrandList.add(list_one.get(2));
                }
                if(list_two.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_two.get(0));
                    articleInfoByArticleBrandList.add(list_two.get(1));
                }
                if(list_three.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_three.get(0));
                }
                if(list_four.size() >= 1) {
                    articleInfoByArticleBrandList.add(list_four.get(0));
                }
                if(list_five.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_five.get(0));
                    articleInfoByArticleBrandList.add(list_five.get(1));
                }

                if(list_one.size() >= 6) {
                    articleInfoByArticleBrandList.add(list_one.get(3));
                    articleInfoByArticleBrandList.add(list_one.get(4));
                    articleInfoByArticleBrandList.add(list_one.get(5));
                }
                if(list_two.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_two.get(2));
                    articleInfoByArticleBrandList.add(list_two.get(3));
                }
                if(list_three.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_three.get(1));
                }
                if(list_four.size() >= 2) {
                    articleInfoByArticleBrandList.add(list_four.get(1));
                }
                if(list_five.size() >= 4) {
                    articleInfoByArticleBrandList.add(list_five.get(2));
                    articleInfoByArticleBrandList.add(list_five.get(3));
                }
            }
        }

        /**
         *
         * 4、用户关注4个品牌：
         *
         * 品牌1 三篇 + 品牌2 两篇 +正能量+健康+ 品牌3两篇 + 品牌4两篇  + 循环
         */
        if(userBrandIds.size() == 4) {
            if (!isToday) {
                // 3篇关注的品牌1
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 3);
                // 2篇关注的品牌2
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(1), 2);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 1);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(2), 2);
                // 2篇关注的品牌4
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(3), 2);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);

                redisCacheUtil.setCacheObject(verifyKey, ToolUtil.getTodayYMD(), SysConstant.LOOK_ARTICLE_TYPE_EXPIRATION);
            }

            if (isToday) {
                // 3篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 3);
                // 2篇关注的品牌
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(1), 2);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 1);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(2), 2);
                // 2篇关注的品牌4
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(3), 2);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);
            }
        }

        /**
         *
         * 5、用户关注5个品牌：
         *
         * 品牌1 三篇 + 品牌2 两篇 +正能量+健康+ 品牌3两篇 + 品牌4两篇  + 品牌5 两篇+循环
         */
        if(userBrandIds.size() >= 5) {
            if (!isToday) {
                // 3篇关注的品牌1
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(0), 3);
                // 2篇关注的品牌2
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(1), 2);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.queryArticleInfoOfBrandOrType(2, 1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.queryArticleInfoOfBrandOrType(2, 4, 1);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(2), 2);
                // 2篇关注的品牌4
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(3), 2);
                // 2篇关注的品牌5
                List<CombinedArticleInfoByArticleBrand> list_seven = articleInfoService.queryArticleInfoOfBrandOrType(1, userBrandIds.get(4), 2);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);
                articleInfoByArticleBrandList.addAll(list_seven);

                redisCacheUtil.setCacheObject(verifyKey, ToolUtil.getTodayYMD(), SysConstant.LOOK_ARTICLE_TYPE_EXPIRATION);
            }

            if (isToday) {
                // 3篇关注的品牌1
                List<CombinedArticleInfoByArticleBrand> list_one = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(0), 3);
                // 2篇关注的品牌2
                List<CombinedArticleInfoByArticleBrand> list_two = articleInfoService.getArticleInfoByBrandForRandTop50(userBrandIds.get(1), 2);
                // 1篇正能量(1)
                List<CombinedArticleInfoByArticleBrand> list_three = articleInfoService.getArticleInfoByArticleTypeForRandTop50(1, 1);
                // 1篇健康(4)
                List<CombinedArticleInfoByArticleBrand> list_four = articleInfoService.getArticleInfoByArticleTypeForRandTop50(4, 1);
                // 2篇关注的品牌3
                List<CombinedArticleInfoByArticleBrand> list_five = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(2), 2);
                // 2篇关注的品牌4
                List<CombinedArticleInfoByArticleBrand> list_six = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(3), 2);
                // 2篇关注的品牌5
                List<CombinedArticleInfoByArticleBrand> list_seven = articleInfoService.getArticleInfoByBrandForRandTop50( userBrandIds.get(4), 2);

                articleInfoByArticleBrandList.addAll(list_one);
                articleInfoByArticleBrandList.addAll(list_two);
                articleInfoByArticleBrandList.addAll(list_three);
                articleInfoByArticleBrandList.addAll(list_four);
                articleInfoByArticleBrandList.addAll(list_five);
                articleInfoByArticleBrandList.addAll(list_six);
                articleInfoByArticleBrandList.addAll(list_seven);
            }
        }

        return articleInfoByArticleBrandList;
    }

    /**
     * 获取用户生成的或修改的文章
     * @param userId 用户ID
     * @param type 类型：0-全部 1-用户生成的 2-用户修改的
     * @return 文章列表
     */
    @GetMapping(value = "/getUserCreateArticle", produces = "application/json;charset=UTF-8")
    public RespData getUserCreateOrModifyArticle(@RequestHeader("userId") String userId, @RequestParam Integer type) {
        List<ArticleInfo> articleInfos = articleInfoService.getUserCreateOrModifyArticle(Integer.valueOf(userId), type);

        if (CollectionUtils.isNotEmpty(articleInfos)) {
            articleInfos.forEach(info -> {
                info.setArticleHotValue(new Random().nextInt(5000)%(5000-500+1) + 500);
            });
        }

        HashMap<String, Object> resultMap = Maps.newHashMapWithExpectedSize(10);
        resultMap.put("articleInfos", articleInfos);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }

    /**
     * 获取用户文章底部开关设置信息
     * @param userId 用户 ID
     * @param userArticleTailSetReqBean 文章相关信息
     * @return 文章底部开关设置信息
     */
    @PostMapping(value = "/getArticleTailSetInfo", produces = "application/json;charset=UTF-8")
    public RespData getArticleTailSetInfo(@RequestHeader("userId") String userId, @RequestBody UserArticleTailSetReqBean userArticleTailSetReqBean) {
        if (Objects.isNull(userArticleTailSetReqBean) || Objects.isNull(userArticleTailSetReqBean.getArticleId())
//            || Objects.isNull(userArticleTailSetReqBean.getArticleOwner())) {
            ) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

//        Integer articleOwner = userArticleTailSetReqBean.getArticleOwner();
        Integer articleId = userArticleTailSetReqBean.getArticleId();

        Integer finalUserId = Integer.valueOf(userId);
        Integer currentArticleUserId = articleInfoService.getArticleUserInfo(articleId);

        // 如果根据当前文章 ID 获取到的用户 ID 不为空且等于该文章的所有者，则表示该文章属于用户文章
        if (Objects.nonNull(currentArticleUserId) && !currentArticleUserId.equals(userId)) {
            finalUserId = currentArticleUserId;
        }

        int articleAdvertSwitchStatus = 1;// 文章底部广告开关：0-关闭 1-开启
        int articleTableSwitchStatus = 0;// 文章底部表单开关：0-关闭 1-开启
        HashMap<String, Object> resultMap = Maps.newHashMapWithExpectedSize(10);

        // 会员状态
        Integer userVipStatus = userInfoService.getUserVipStatus(finalUserId);
        resultMap.put("userVipStatus", userVipStatus);

        // 获取用户文章底部的按钮开启信息
        UserArticleTailSetInfo articleTailSetInfo = articleInfoService.getArticleTailSetInfo(finalUserId, articleId);

        if (Objects.nonNull(articleTailSetInfo)) {
            articleAdvertSwitchStatus = Optional.ofNullable(articleTailSetInfo.getArticleAdvertSwitchStatus()).orElse(1);
            articleTableSwitchStatus = Optional.ofNullable(articleTailSetInfo.getArticleTableSwitchStatus()).orElse(0);
        } else {
            // 如果查看总开关
            UserArticleTailSwitchSet userArticleTailSwitchSet = userInfoService.getUserArticleTailSwitchSet(finalUserId);
            if (Objects.nonNull(userArticleTailSwitchSet)) {
                articleAdvertSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getAdvertSwitchStatus()).orElse(1);
                articleTableSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getTableSwitchStatus()).orElse(0);
            }
        }

        resultMap.put("articleAdvertSwitchStatus", articleAdvertSwitchStatus);
        resultMap.put("articleTableSwitchStatus", articleTableSwitchStatus);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }

    /**
     * 修改用户文章底部开关设置信息
     * @param userId 用户 ID
     * @param articleTailSetInfoReqBean 用户文章底部开关设置的请求实体类
     * @return 操作信息
     */
    @PostMapping(value = "/updateArticleTailSetInfo", produces = "application/json;charset=UTF-8")
    public RespData updateArticleTailSetInfo(@RequestHeader("userId") String userId, @RequestBody ArticleTailSetInfoReqBean articleTailSetInfoReqBean) {
        if (Objects.isNull(articleTailSetInfoReqBean) || Objects.isNull(articleTailSetInfoReqBean.getArticleId())
            || (/*Objects.isNull(articleTailSetInfoReqBean.getArticleAdvertSwitchStatus()) &&*/ Objects.isNull(articleTailSetInfoReqBean.getArticleTableSwitchStatus()))) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        // 查询用户该文章的设置状态
        UserArticleTailSetInfo userArticleTailSetInfo = articleInfoService.getArticleTailSetInfo(Integer.valueOf(userId), articleTailSetInfoReqBean.getArticleId());

        // 如果有，则更新；反之，则新增
        if (Objects.nonNull(userArticleTailSetInfo)) {
            ArticleTailSetInfo articleTailSetInfo = new ArticleTailSetInfo();
            articleTailSetInfo.setUserId(Integer.parseInt(userId));
            articleTailSetInfo.setArticleId(articleTailSetInfoReqBean.getArticleId());
            /*if (Objects.nonNull(articleTailSetInfoReqBean.getArticleAdvertSwitchStatus())) {
                articleTailSetInfo.setArticleAdvertSwitchStatus(articleTailSetInfoReqBean.getArticleAdvertSwitchStatus());
            }*/
            if (Objects.nonNull(articleTailSetInfoReqBean.getArticleTableSwitchStatus())) {
                articleTailSetInfo.setArticleTableSwitchStatus(articleTailSetInfoReqBean.getArticleTableSwitchStatus());
            }
            articleTailSetInfo.setModifyTime(DateUtil.getCurDate());

            articleInfoService.updateArticleTailSetInfo(articleTailSetInfo);
        } else {
            Integer advertSwitchStatus = Integer.valueOf(1);// 广告总开关 0-关闭 1-启用 默认启用
            Integer tableSwitchStatus = Integer.valueOf(1);// 文章底部表格总开关 0-关闭 1-启用 默认关闭

            // 获取用户广告和文章底部表格总开关开启状态信息
            UserArticleTailSwitchSet userArticleTailSwitchSet = userInfoService.getUserArticleTailSwitchSet(Integer.valueOf(userId));
            if (Objects.nonNull(userArticleTailSwitchSet)) {
                advertSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getAdvertSwitchStatus()).orElse(1);
                tableSwitchStatus = Optional.ofNullable(userArticleTailSwitchSet.getTableSwitchStatus()).orElse(1);
            }

            ArticleTailSetInfo articleTailSetInfo = new ArticleTailSetInfo();
            articleTailSetInfo.setUserId(Integer.parseInt(userId));
            articleTailSetInfo.setArticleId(articleTailSetInfoReqBean.getArticleId());

            /*if (Objects.nonNull(articleTailSetInfoReqBean.getArticleAdvertSwitchStatus())) {
                articleTailSetInfo.setArticleAdvertSwitchStatus(articleTailSetInfoReqBean.getArticleAdvertSwitchStatus());
            } else {
                articleTailSetInfo.setArticleAdvertSwitchStatus(advertSwitchStatus);
            }*/

            if (Objects.nonNull(articleTailSetInfoReqBean.getArticleTableSwitchStatus())) {
                articleTailSetInfo.setArticleTableSwitchStatus(articleTailSetInfoReqBean.getArticleTableSwitchStatus());
            } else {
                articleTailSetInfo.setArticleTableSwitchStatus(tableSwitchStatus);
            }

            articleTailSetInfo.setCreateTime(DateUtil.getCurDate());

            articleInfoService.addArticleTailSetInfo(articleTailSetInfo);
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;
    }

}
